Certificate Installation Access Denied Error

大憨熊 提交于 2019-12-23 18:55:02

问题


I am trying to add a certificate inside localMachine Root. Below is the code for what I tried but this is not allowing me to add into Local Machine, while coming to add it say's access denied. How to allow to install inside Local Machine?

X509Certificate2 cert = new X509Certificate2(@"D:\MyCertificate.pfx", "Temp@1234",
                X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);
// save certificate and private key
X509Store storeMy = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
storeMy.Open(OpenFlags.ReadWrite);
storeMy.Add(cert);

回答1:


Make sure Identity property of Application Pool you are using for your application is set to Local System.




回答2:


Try to Run application as Admin.

If it works successfully as an admin that means your user doesn't have access to install the certificate.

Please read through this

You can try to install the certificate under current user store rather than local machine.

In code use:

StoreLocation.CurrentUser

instead of

StoreLocation.LocalMachine


来源:https://stackoverflow.com/questions/18637238/certificate-installation-access-denied-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!