【问题标题】:Azure Web App calling on-prem service with Self-Signed SSL CertAzure Web App 使用自签名 SSL 证书调用本地服务
【发布时间】:2023-04-07 07:01:01
【问题描述】:

我们有一个 Azure Web 应用程序需要通过 VPN 调用内部 Web 服务

我们已配置所有内容,但由于我们的非生产内部服务器上的 Web 服务使用自签名证书,调用失败:

远程证书根据验证无效 过程。

我们可以在本地将 .cer 导入 Trusted People。

如何在 Azure 上实现这一点?

【问题讨论】:

    标签: azure ssl ssl-certificate self-signed


    【解决方案1】:

    您无法将 .cer 文件导入 Azure Web App 服务器。如果您可以修改您的代码,您可以实施一种解决方法,创建您自己的证书验证。一个例子:

        ServicePointManager.ServerCertificateValidationCallback += (
            object sender,
            X509Certificate certificate,
            X509Chain chain,
            SslPolicyErrors sslPolicyErrors) =>
        {
            if (sslPolicyErrors == SslPolicyErrors.None)
            {
                return true;
            }
            else
            {
                var myGoodCert = X509Certificate.CreateFromCertFile(Server.MapPath("~/path/to/mycert.cer"));
                return myGoodCert.Equals(certificate);  // compares issuer and serial number
            }          
        };
    

    记得将 .cer 文件与您的 Web 应用程序文件一起部署,或将其放置在您的 Web 应用程序可访问的位置(azure blob 存储、sql 上的 blob 等)

    【讨论】:

    • 我应该把这个放在哪里?我在 Application_Start 中尝试过,但出现错误:Server operation is not available in this context.
    • 想通了。在调用 WS 之前,我把它放在了我的 MVC 控制器中,它起作用了!惊人的。谢谢!
    猜你喜欢
    • 2015-10-21
    • 1970-01-01
    • 2019-01-05
    • 2013-07-18
    • 2020-05-04
    • 1970-01-01
    • 2019-06-30
    • 2018-10-02
    • 2020-04-29
    相关资源
    最近更新 更多