I wish to import a Certificate from a C# app into IIS.
If I import the file using the IIS manager GUI:
- Server Certificates
It allows me to use this to assign as the SSL certificate in the Site Binding.
Now, if I do the same process within C#, it adds the certificate - or at least it looks identical - but when I try to assign it as the SSL certificate in the Site Binding, it gives the error:
"A specified logon session does not exist. It may already have been terminated. (Exception from HRESULT: 0x80070520)"
When you view the certificate in the 'Server Certificates' dialog it has identical entries for each of the columns...
The code I am using is as follows:
X509Store store = new X509Store("WebHosting", StoreLocation.LocalMachine); store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadWrite);X509Certificate2 certificate = new X509Certificate2(xSSLCertificate, xSSLCertificatePassword);store.Add(certificate);store.Close();
IIS Forum Thread: https://forums.iis.net/t/1163325.aspx
Other reference links: