.NET 证书 (C#)
我的网站正在向另一台服务器发送一些 http 帖子,我需要附加证书。
我使用此代码打开证书存储并获取我需要的证书:
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509CertificateCollection certCollection = store.Certificates;
用户是域帐户,应用程序的应用程序池使用它。
问题是我只有在该帐户登录到计算机时才能获得证书。如果用户注销,我将无法访问该商店。
有什么想法吗?
谢谢!
My website is doing some http posts to another server and I need to attach a certificate.
I am using this code to open the certificate store and getting the certificate I need:
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509CertificateCollection certCollection = store.Certificates;
The user is a domain account and the application pool for the application uses it.
The problem is that I only get the certificate if that account is logged in into the machine. If the user is logged off I cannot access this store.
Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将证书从 CurrentUser Windows 证书存储移动到 LocalMachine 存储(例如,使用证书 MMC 控制台),然后将 X509Store 构造函数的参数从 StoreLocation.CurrentUser 更改为 StoreLocation.LocalMachine。
另一种选择是将证书存储在 PFX 文件中并从那里加载它,但您需要注意从磁盘加载 PFX 文件时使用的密码的安全性。
You need to move certificate from CurrentUser windows certificate storage to LocalMachine storage (eg. using Certificates MMC console), then change parameters of your X509Store constructor from StoreLocation.CurrentUser to StoreLocation.LocalMachine.
Another option is to store certificate in PFX file and load it from there, but you need to take care about security of the password used when loading PFX file from disk.