【问题标题】:Azure App Services - Can't find certificate by thumbprintAzure 应用服务 - 无法通过指纹找到证书
【发布时间】:2017-06-21 09:37:55
【问题描述】:

我在 Azure 中有一个 B1 应用服务,我已经在其中安装了我的证书,如下所示:

当我尝试获取证书时,它找不到它。好像没有安装证书一样。这是我的代码:

using (X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser))
{
    certStore.Open(OpenFlags.ReadOnly);
    X509Certificate2Collection certCollection = certStore.Certificates.Find(
        X509FindType.FindByThumbprint,
        certificateThumbprint,
        false);

    if (certCollection.Count > 0)
    {
        return certCollection[0];
    }

    throw new Exception("Certificate not found!");
}

我已经验证了证书指纹,甚至尝试将其硬编码为字符串。

当我尝试像这样打印商店中的证书数量时:

Console.WriteLine("certStore.Certificates.Count : " + certStore.Certificates.Count);

它返回零个证书。

我还尝试更改 StoreNameStoreLocation - 结果仍然相同。即使没有提供任何StoreNameStoreLocation,它仍然找不到任何证书。

【问题讨论】:

    标签: azure ssl azure-web-app-service


    【解决方案1】:

    您需要添加一个名为:WEBSITE_LOAD_CERTIFICATES

    的应用设置

    来自https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/?v=17.23h

    添加一个名为 WEBSITE_LOAD_CERTIFICATES 的应用设置,并将其值设置为证书的指纹,这将使您的网络应用程序可以访问它。您可以有多个以逗号分隔的指纹值,或者可以将此值设置为“*”(不带引号),在这种情况下,您的所有证书都将加载到您的 Web 应用程序个人证书存储中。

    【讨论】:

    • 仅供参考,您可以使用 Kudu 中的 powershell 控制台导航到以下路径,然后在其上运行 LS 命令 cert:\localmachine\currentuser
    • 谢谢!我在 2 年前将其配置为特定的证书,但无法弄清楚为什么该函数不会加载更新的证书。这篇文章引发了一个 aha 时刻。谢谢!!!
    猜你喜欢
    • 2014-07-03
    • 2012-09-18
    • 2014-07-10
    • 2019-09-28
    • 2020-01-20
    • 2021-05-28
    • 2014-09-16
    • 2012-06-22
    • 2021-06-27
    相关资源
    最近更新 更多