Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将证书添加到X509Store_C#_X509certificate - Fatal编程技术网

C# 无法将证书添加到X509Store

C# 无法将证书添加到X509Store,c#,x509certificate,C#,X509certificate,我正试图以编程方式将证书添加到证书存储中 我正在使用以下代码从目录中获取一个pfx文件,并将证书添加到我的存储下的CurrentUser。 代码运行时没有任何异常,但我无法看到存储中添加的证书。 我尝试将CurrentUser更改为LocalMachine,并尝试添加UnderTrustedPeople,但没有成功 X509Certificate2 cer = new X509Certificate2(Server.MapPath("<filepath>"), "<pswd&g

我正试图以编程方式将证书添加到证书存储中 我正在使用以下代码从目录中获取一个pfx文件,并将证书添加到我的存储下的CurrentUser。 代码运行时没有任何异常,但我无法看到存储中添加的证书。 我尝试将CurrentUser更改为LocalMachine,并尝试添加UnderTrustedPeople,但没有成功

X509Certificate2 cer = new X509Certificate2(Server.MapPath("<filepath>"), "<pswd>", X509KeyStorageFlags.MachineKeySet );
                StorePermission sp =
            new StorePermission(PermissionState.Unrestricted);
            sp.Flags = StorePermissionFlags.AllFlags;
            sp.Assert();
            X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            store.Open(OpenFlags.MaxAllowed);
            store.Certificates.Add(cer);
        store.Close();
X509Certificate2 cer=新的X509Certificate2(Server.MapPath(“”,“),X509KeyStrageFlags.MachineKeySet);
存储权限sp=
新的StorePermission(PermissionState.Unrestricted);
sp.Flags=StorePermissionFlags.AllFlags;
sp.Assert();
X509Store=新的X509Store(StoreName.My,StoreLocation.CurrentUser);
store.Open(OpenFlags.MaxAllowed);
存储.证书.添加(cer);
store.Close();

您如何知道代码成功?您是否已将其包装在一个
try/catch
中,并在catch块中设置了断点?是的,我已将其放入try-catch中,但没有例外。另外,如果我在Add语句之后调试并检查store.Certificates集合,则新证书不会添加到其中。