使用Microsoft.Web.Administration以编程方式安装SSL证书

问题描述:

因此 Microsoft.Web.Administration API非常易于用于为网站创建HTTP和HTTPS绑定:

So the Microsoft.Web.Administration API is very easy to use to create HTTP and HTTPS bindings for sites:

using (ServerManager manager = new ServerManager())
{
    Site site = manager.Sites[siteName];
    site.Bindings.Clear();
    site.Bindings.Add("*:80:", "http");
    site.Bindings.Add("*:443:", "https");

    manager.CommitChanges();
}

但如果没有SSL证书,HTTPS绑定就毫无意义。如何使用此API以编程方式选择证书文件并将其与HTTPS绑定一起使用?

But the HTTPS binding is pretty meaningless without the SSL certificate. How can I go about programatically choosing a cert file and using it with the HTTPS binding, using this API?

有一个方法重载,用于添加将证书正确添加到HTTP.sys的Bindings,请参阅: http://msdn.microsoft.com/en-us/library/bb355650(v = VS.90).aspx

There is a method overload for adding Bindings that will add the certificate to HTTP.sys correctly, see: http://msdn.microsoft.com/en-us/library/bb355650(v=VS.90).aspx

您可以选择实际设置绑定设置:

Optionally you can actually set the binding settings:

binding.CertificateHash和binding.CertificateStoreName以及提交时将使用HTTP.sys正确注册:
http://msdn.microsoft。 com / en-us / library / microsoft.web.administration.binding_properties(v = VS.90).aspx

binding.CertificateHash and binding.CertificateStoreName and when commiting it will register correctly with HTTP.sys: http://msdn.microsoft.com/en-us/library/microsoft.web.administration.binding_properties(v=VS.90).aspx