据我了解,如果有人不想使用自定义域名,而是计划使用 Azure 分配给网站的 *.azurewebsite.net 域,那么已经使用 Microsoft 的证书启用了 HTTPS(我知道这并不像与使用自定义域名一样安全)。我如何才能以编程方式加载此证书。目前我使用以下方法从本地计算机或Azure加载证书:
public static X509Certificate2 LoadFromStore(string certificateThumbprint,bool hostedOnAzure)
{
var s = certificateThumbprint;
var thumbprint = Regex.Replace(s, @"[^\da-zA-z]", string.Empty).ToUpper();
var store = hostedOnAzure ? new X509Store(StoreName.My, StoreLocation.CurrentUser) : new X509Store(StoreName.Root, 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 certificate store. Also number of certificates in the sotre was {1}", thumbprint, store.Certificates.Count));
}
return signingCert[0];
}
finally
{
store.Close();
}
}
我认为罪魁祸首是以下代码行:
new X509Store(StoreName.My, StoreLocation.CurrentUser)
因为当我收到异常时,它告诉我商店中没有证书,尽管我传递了正确的证书指纹(我手动从 Chrome 获取指纹)。
您将无法在 Web 应用程序中以编程方式访问此证书,因为此证书并未真正安装在 Azure Web 应用程序上。 Azure WebApps 有一个前端服务器,它执行“某种”SSL 卸载,因此 WebApp 实际上永远无法访问此特定证书。您到底为什么要阅读这份证书?
通常,如果 Web 应用程序需要证书,您将安装客户证书并将它们传递给服务进行身份验证,如中所述https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/ https://azure.microsoft.com/en-us/blog/using-certificates-in-azure-websites-applications/以及您可以通过编程方式访问的那些证书(同一篇文章中提到的代码片段)
但我不确定你到底想通过阅读达到什么目的服务器证书
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)