The web server received an invalid response, acting as a gateway or proxy server

When you try to deploy a web application to Azure using a service account in the Google.net client library, it returns with the following error

502 - The web server received an invalid response, acting as a gateway or proxy server.

Code example:

var certificate = new X509Certificate2(KeyFilePath, "notasecret", X509KeyStorageFlags.Exportable); ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail) { Scopes = new string[] { AnalyticsService.Scope.Analytics }; }.FromCertificate(certificate)); // Create the service. AnalyticsService service = new AnalyticsService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Analytics API Sample", }); 

When starting in development, the code above is given. However, when deployed to AZURE, it returns an error.

+6
source share
1 answer

It took me about 2 hours to track the problem

The problem is how Azure deals with certificates.

Changing the following line

 var certificate = new X509Certificate2(KeyFilePath, "notasecret", X509KeyStorageFlags.Exportable); 

to that

 var certificate = new X509Certificate2(KeyFilePath, "notasecret", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable); 

The web application and service account now run on Azure. Hope this helps someone in the future.

+7
source

All Articles