c# - Azure Functions 不断返回 'The credentials supplied to the package were not recognized'

标签 c# azure azure-functions tls1.2 client-certificates

我有一个 Azure Functions,它不断向我返回“无法识别提供给包的凭据”。证书(pfx 格式)已作为私钥证书上传到 Azure - 请参阅下图 - 并且状态良好,我可以读取其中的 3 个证书。

enter image description here

我还设置了 appSettings WEBSITE_LOAD_USER_PROFILE=1 和 WEBSITE_LOAD_CERTIFICATES=thumbprints 但没有运气。这是我的函数应用程序的应用程序设置。

enter image description here

这是我在处理证书时使用的代码。我正在关注 Microsoft 的官方文档 - https://learn.microsoft.com/da-dk/azure/app-service/configure-ssl-certificate-in-code#load-certificate-in-windows-apps

using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

string certThumbprint = "certThumbprint";
bool validOnly = false;

using (X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser))
{
  certStore.Open(OpenFlags.ReadOnly);

  X509Certificate2Collection certCollection = certStore.Certificates.Find(
                              X509FindType.FindByThumbprint,
                              // Replace below with your certificate's thumbprint
                              certThumbprint,
                              validOnly);
  // Get the first cert with the thumbprint
  X509Certificate2 cert = certCollection.OfType<X509Certificate>().FirstOrDefault();

  if (cert is null)
      throw new Exception($"Certificate with thumbprint {certThumbprint} was not found");

  // Use certificate
  Console.WriteLine(cert.FriendlyName); 
}

最佳答案

总结作者提供的评论,供其他社区引用:

该问题是由以下代码行引起的:X509Certificate2 cert = certCollection.OfType<X509Certificate>().FirstOrDefault();

将代码行更改为:if (certCollection.Count > 0) { return certCollection[0]; } ,然后就可以了。

关于c# - Azure Functions 不断返回 'The credentials supplied to the package were not recognized',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66439008/

相关文章:

c# - 如何让一个简单的超链接在 XAML 中工作?

azure - 将 Azure Bot 与 Azure 语音服务集成

azure-functions - System.Private.Uri : Value cannot be null error with Azure Function

Azure Function 不遵循 CRON 计时器计划

azure - 如何绑定(bind)到 ICloudBlob 或其他某种(非字符串)类型

c# - Path.GetFilename - 尝试从目录中获取文件名

c# - 由于其权限而无法访问套接字

c# - 为什么 Blazor 不会路由到 Razor 库中的组件?

asp.net - 表被同一记录多次更新

php - Azure 网站 : Error connecting to Twilio "SSL certificate pro blem: unable to get local issuer certificate (0)"