Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web server received an invalid response while acting as a gateway or proxy server

When trying to deploy a web application to Azure using a service account with the Google .net client library it is returning with the following error

502 - Web server received an invalid response while 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",
                });

The code above works when run in development. However when deployed to AZURE it returns an error.

like image 817
DaImTo Avatar asked Sep 02 '15 18:09

DaImTo


1 Answers

It has taken me about 2 hours to track down the problem

The issue is to do with the with the way that Azure deals with certificates.

By changeing the following line

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

to this

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

The web application and the service account now work on Azure. I hope this helps someone in the future.

like image 134
DaImTo Avatar answered Sep 19 '22 20:09

DaImTo