使用Web应用程序访问客户端证书

时间:2019-01-10 15:54:45

标签: c# asp.net asp.net-mvc asp.net-core

我需要获取证书,并希望获取客户端,并且没有服务器,所以我可以这样做:

public static X509Certificate2 EscolherCertificado(string serial)
    {
    X509Store userCaStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
    try
    {
        userCaStore.Open(OpenFlags.ReadOnly);
        X509Certificate2Collection certificatesInStore = userCaStore.Certificates;
        X509Certificate2Collection findResult = certificatesInStore.Find(X509FindType.FindBySerialNumber, serial, true);
        X509Certificate2 clientCertificate = null;
        if (findResult.Count == 1)
        {
            clientCertificate = findResult[0];
        }
        else
        {
            throw new Exception("Unable to locate the correct client certificate.");
        }
        cod = "0000"; msgm = clientCertificate.ToString(); return clientCertificate;
    }
    catch
    {
        throw;
    }
    finally
    {
        userCaStore.Close();
    }

这样,它就可以在本地工作,但是当我发布它时却找不到证书,我该如何解决呢?证书无法保留在服务器上,使用的证书是A3智能卡。

编辑

我以为我可能做错了什么,但是在检查此link时,发生了同样的事情,当发布到服务器不起作用时,它只能在本地工作。任何想法 ?

0 个答案:

没有答案
相关问题