我正在尝试在Asp.NET Core 1.1应用程序中使用Apple推送证书,但它找不到任何证书。
我上传了证书并将WEBSITE_LOAD_CERTIFICATES设置为*(全部)。
以下代码是我用来获取证书的代码
var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
try
{
store.Open(OpenFlags.ReadOnly);
var certCollection = store.Certificates;
var signingCert = certCollection.Find(X509FindType.FindByThumbprint, thumbprint, false);
if (signingCert.Count == 0)
{
throw new FileNotFoundException(string.Format("Cert with thumbprint: '{0}' not found in local machine cert store.", thumbprint));
}
return signingCert[0];
}
我错过了什么?
答案 0 :(得分:1)
您似乎想upload your certificate to the certificates collection in Azure Websites and consume it in your web application from your site’s personal certificate store。我上传了我的证书并使用以下代码在Asp.NET Core 1.1应用程序中使用它,该代码适用于我。
X509Certificate2 retVal = null;
var thumbprint = "{cert_thumbprint}";
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var certCollection = store.Certificates;
var signingCert = certCollection.Find(X509FindType.FindByThumbprint, thumbprint, false);
if (signingCert.Count > 0)
{
retVal = signingCert[0];
}
远程调试代码,代码在azure网站上正常运行