尝试使用具有Google .net客户端库的服务帐户将Web应用程序部署到Azure时,它返回时出现以下错误
502 – Web server received an invalid response while acting as a
gateway or proxy server.
代码示例:
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",});
解决方法
我花了大约2个小时来追查问题
问题与Azure处理证书的方式有关.
通过更改以下行
var certificate = new X509Certificate2(KeyFilePath,X509KeyStorageFlags.Exportable);
对此
var certificate = new X509Certificate2(KeyFilePath,X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
Web应用程序和服务帐户现在可以在Azure上运行.我希望这可以帮助将来的某个人.