-1

I'm using this code to import a certicifate from a PFX file:

string certPath = @"C:\a\something.eu.pfx";
string certPass = "password";

// Create a collection object and populate it using the PFX file
X509Certificate2 certifikat = new X509Certificate2();
certifikat.Import(certPath, certPass, X509KeyStorageFlags.PersistKeySet);

X509Store store = new X509Store();
store.Open(OpenFlags.MaxAllowed);
store.Add(certifikat);
store.Close();

It executes without errors, but the certificate doesn't appear in the "Web Hosting" store. How can I import it in that store?

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
Vítek S.
  • 29
  • 6
  • Yes i run it on webserver. And in mmc under certificates you can find folder webhosting and there i want to import it. – Vítek S. Dec 14 '16 at 10:06

1 Answers1

1

Using the X509Store constructor you can specify which store you want to open. You'll want the "Web Hosting" store (internal name: "WebHosting") for the local machine, so construct the class like this:

var store = new X509Store("WebHosting", StoreLocation.LocalMachine);
CodeCaster
  • 147,647
  • 23
  • 218
  • 272