X509Store Certificates.Find()间歇性地找不到证书

Sha*_*son 7 c# asp.net-mvc client-certificates certificate-store x509

我有一个MVC Web应用程序的问题,它使用私有证书调用另一个服务.

证书位于我的个人密钥库中,针对当前计算机 - 我曾经winhttpcertcfg将证书的权限授予我的Web应用程序的应用程序池标识.密钥按以下方法加载;

internal bool SetCertificateFromCertStore(string subjectName)
{
    X509Store store = null;
    try
    {
        store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
        store.Open(OpenFlags.ReadOnly);
        X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySubjectName, subjectName, true);
        if (certs.Count != 1)
        {
            store.Close();
            store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadOnly);
            certs = store.Certificates.Find(X509FindType.FindBySubjectName, subjectName, true);
            if (certs.Count != 1)
            {
                throw new Exception("Unable to find Certificate");
            }
        }
        _certificate = certs[0];
        return true;
    }
    finally
    {
        if (store != null)
        {
            store.Close();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这个代码每次都工作到几周前(4月12日),当时在17:05我注意到ELMAH中第一个出现"无法找到证书"异常的例子.检查应用程序日志,系统仍在处理几乎所有请求,此错误在某些请求上每小时只会出现几次.

我已经阅读了类似的问题,建议实现类似于我已经使用的代码(查询多个商店).Windows证书存储是否存在某种已知问题?也许一个锁定问题?还有另一种方法可以解决这个或明显的问题我在这里做错了吗?

您可以提供的任何帮助都将受到赞赏,因为我已经用尽了一些东西!