從Web應用程序運行此代碼時,我看不到任何X509證書讀取證書存儲X509證書:不能在Web應用程序
var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
string thumbprint = WebConfigurationManager.AppSettings["CertificateThumbprint"];
if (string.IsNullOrWhiteSpace(thumbprint))
{
throw new ArgumentException("Please specify the X509 certificate thumbprint in the web configuration file.");
}
Certificate = store.Certificates
.Find(X509FindType.FindByThumbprint, thumbprint, true)
.OfType<X509Certificate2>()
.FirstOrDefault();
store.Close();
if (Certificate == null)
{
throw new ArgumentException("The specified X509 certificate has not been installed on this server.");
}
調試時,我可以看到store.Certificates
是空的。然而,它在控制檯應用程序中運行得非常好..這很奇怪,因爲我在網上應用程序中使用上述代碼在線查看了示例。
如果代碼會拋出某種權限異常或Web應用程序中的某些內容來告訴我爲什麼我無法讀取它們,但它不會。那麼,我需要在某處設置一些權限嗎?