0

I need to populate system certificates. Same source code tells me the certificates count correctly when I debug it under VS. When I run the code under IIS 7.5 Windows 7, .Count always returns 0. Is there any permission problem? Why does the count return 0?

        System.Security.Cryptography.X509Certificates.X509Store store = new System.Security.Cryptography.X509Certificates.X509Store(System.Security.Cryptography.X509Certificates.StoreName.My);
        store.Open(System.Security.Cryptography.X509Certificates.OpenFlags.ReadOnly);
        Response.Write("<hr>Certs count: " + store.Certificates.Count.ToString() + "<br>");
Nime Cloud
  • 6,162
  • 14
  • 43
  • 75

2 Answers2

0

IIS and VS debugger run under different user credentials. So IIS cannot load the certificates. Here is my workaround:

I'll make a commandline utility and run it as user

Nime Cloud
  • 6,162
  • 14
  • 43
  • 75
0

ASP.NET Impersonation helps to load user's certificates.

P.S: System.Security.Principal.WindowsIdentity.GetCurrent().Name gets the user name.

Nime Cloud
  • 6,162
  • 14
  • 43
  • 75