views:

49

answers:

1

Hello,

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!

+1  A: 

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.

Eugene Mayevski 'EldoS Corp