c# – Web服务器在充当网关或代理服务器时收到无效响应

c# – Web服务器在充当网关或代理服务器时收到无效响应,第1张

概述尝试使用具有Google .net客户端库的服务帐户将Web应用程序部署到Azure时,它返回时出现以下错误 502 – Web server received an invalid response while acting as a gateway or proxy server. 代码示例: var certificate = new X509Certificate2(KeyFilePath 尝试使用具有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",});

上面的代码在开发中运行时有效.但是,当部署到AZURE时,它会返回错误.

解决方法 我花了大约2个小时来追查问题

问题与Azure处理证书的方式有关.

通过更改以下行

var certificate = new X509Certificate2(KeyfilePath,X509KeyStorageFlags.Exportable);

对此

var certificate = new X509Certificate2(KeyfilePath,X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);

Web应用程序和服务帐户现在可以在Azure上运行.我希望这可以帮助将来的某个人.

总结

以上是内存溢出为你收集整理的c# – Web服务器在充当网关或代理服务器时收到无效响应全部内容,希望文章能够帮你解决c# – Web服务器在充当网关或代理服务器时收到无效响应所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1247737.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存