我使用以下方法从x509商店获取证书
private X509Certificate GetCert(string certThumbPrint)
{
var certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
certStore.Open(OpenFlags.ReadOnly);
var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, certThumbPrint.Trim(), false);
certStore.Close();
// Check to see if our certificate was added to the collection. If no, throw an error, if yes, create a certificate using it.
if (0 == certCollection.Count || certCollection.Count == null)
{
throw new ApiException(string.Format("Error: Admin Service Client : No certificate found containing thumbprint {0}",certThumbPrint), ApiLogCategory.Configuration, ErrorCodes.AdminServiceClient);
}
var cert = new X509Certificate(certCollection[0].RawData, string.Empty, X509KeyStorageFlags.MachineKeySet);
return cert;
}
我收到错误,所以我尝试调试,发现应用程序无法打开X509商店。在这种情况下我能做些什么。
答案 0 :(得分:0)
它看起来像是与权限相关的问题。
您的证书是否已安装在个人商店?
如果是,请右键单击certificate =>所有任务=>管理私钥=>添加IIS AppPool \ AppPoolName并授予其完全控制
如果您在不同于应用程序池标识的帐户下运行应用程序池,那么该用户。