Can't read CurrentUser certificates from X509Store

帅比萌擦擦* 提交于 2019-12-21 04:36:20

问题


I'm developing ASP.NET 4.0 web application, and I want to read the current user certificates from X509Store. Reading the LocalMachine certificates works fine, but if I set the StoreLocation to CurrentUser, it gives me an empty collection.

The following code works fine :

X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); // StoreLocation.CurrentUser
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

I've checked my personal store (via certmgr.mmc) and I'm sure that I have the certificates.

What am I missing ? ( store.Certificates is empty )


回答1:


It appears that you can not access the Personal Certificate Store via web application, no matter what application pool identity you're using.

It makes sense, a web application has no access to that location. :)

My solution :

I've developed an ActiveX control which I think its the only way to access the Store. (Also, a Java Applet offers the same functionality). I use the ActiveX control via JavaScript to access the Store, and send that information to the server.




回答2:


If your worker process cannot access cert store, maybe it's just account setup problem. Try go ing to IIS Configuration, open ApplicationPools, right click on yours, select Advanced and try setting LoadUserProfile to TRUE. And restart the pool. It worker for me - no more exceptions when loading .PFX with private keys.




回答3:


I had a similar problem. The solution was:

IIS admin->[your virtual dir]->Authentication->Anonymous Authentication (select then click "Edit...") and change it to use "Application pool identity".

Otherwise it may be running as the generic "IUSR"



来源:https://stackoverflow.com/questions/9808667/cant-read-currentuser-certificates-from-x509store

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