我得到了非常奇怪的代码异常,这应该可行但不起作用。
我有以下代码:
X509Certificate certificate;
X509CertificateStore store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore);
store.OpenRead();
var certs = new X509CertificateCollection();
Microsoft.Web.Services2.Security.X509.X509CertificateCollection findCertificateBySubjectName = store.FindCertificateBySubjectName("localhost");
foreach (X509Certificate tempCertificate in store.Certificates)
{
if (String.CompareOrdinal(tempCertificate.Subject, "") == 0)
{
certs.Add(tempCertificate);
}
}
当前代码在管理员权限下的w3wp进程内运行。但是我在截图中看到了异常。我尝试了很多东西,让所有证书都可以访问,更改用户,重新导入证书。 如有任何帮助或帮助,我将不胜感激。