【问题标题】:Where does IIS import cert to?IIS 将证书导入到哪里?
【发布时间】: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


    【解决方案1】:

    由于您没有按要求设置X509KeyStorageFlags.PersistKeySet,因此证书实际上并没有按您的意愿导入到商店中。

    更多解释可以在KB950090找到

    【讨论】:

    • 这正是问题所在!谢谢
    猜你喜欢
    • 2011-05-28
    • 2013-02-05
    • 2011-06-20
    • 2013-10-23
    • 2010-10-21
    • 2019-05-02
    • 2016-04-24
    • 2018-07-02
    • 1970-01-01
    相关资源
    最近更新 更多