【发布时间】:2020-02-27 18:50:52
【问题描述】:
我正在尝试复制 IIS 导入的功能。我有一个应用程序需要以编程方式导入证书,但它无法正常工作,因为我似乎错过了一个步骤。如果我通过 IIS 导入实用程序导入相同的证书,它会完美运行。
在代码中:
private X509Certificate2Collection x509 = new X509Certificate2Collection();
private X509Store IIS = new X509Store(StoreName.My, StoreLocation.LocalMachine);
x509.Import(path, password, X509KeyStorageFlags.Exportable);
var certificate = new X509Certificate2(path, password, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet);
IIS.Open(OpenFlags.ReadWrite);
IIS.Add(certificate);
IIS.Close();
netsh http add sslcert ipport=0.0.0.0:" + port.ToString() + " certhash=" + CertificateThumbprint + " appid={2d967d25-4edf-4962-9b6c-5b3c4d4de48d}";
netsh 绑定失败,错误为a specified logon session does not exist. it may already have been terminated
如果我首先通过 IIS 管理器导入证书,然后运行 netsh 命令,这一切正常,所以我的代码中一定缺少 IIS 在后台执行的操作..
【问题讨论】:
标签: ssl iis ssl-certificate iis-7.5 iis-8