[英]PushSharp Exception : The credentials supplied to the package were not recognized
[英]Azure Functions keep returning 'The credentials supplied to the package were not recognized'
我有一個 Azure 函數不斷返回“無法識別提供給 package 的憑據”。 證書(pfx 格式)已作為私鑰證書上傳到 Azure - 請看下圖 - 狀態為健康,我可以讀取其中的 3 個證書。
我還設置了 appSettings WEBSITE_LOAD_USER_PROFILE=1 和 WEBSITE_LOAD_CERTIFICATES=thumbprints 但沒有運氣。 這是我對 function 應用程序的應用程序設置。
這是我在處理證書時使用的代碼。 我正在關注 Microsoft 的官方文檔 - https://docs.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]; }
if (certCollection.Count > 0) { return certCollection[0]; }
,然后它的工作原理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.