Can't read CurrentUser certificates from X509Store

Tale Masinov picture Tale Masinov · Mar 21, 2012 · Viewed 8.5k times · Source

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 )

Answer

Tale Masinov picture Tale Masinov · Apr 18, 2012

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.