Install SSL certificate programmatically using Microsoft.Web.Administration

前端 未结 7 1724
执念已碎
执念已碎 2020-12-28 20:11

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

using (ServerManager manager = new          


        
7条回答
  •  独厮守ぢ
    2020-12-28 20:32

    The Bindings.Add() method has an overload for passing in the SSL certificate. If you already have a SSL certificate, you can select it from the SSL certificate store like this:

    var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
    store.Open(OpenFlags.OpenExistingOnly);
    var certificate = store.Certificates.Find(X509FindType.FindByThumbprint, the thumbprint for the key", true);
    
    var site = _mgr.Sites[name];
    site.Bindings.Add("*:4043:", certificate[0].GetCertHash(), "MY");
    

    Once you have run the code, you can check that it has worked by running this from the command line:

    netsh http show sslcert
    

提交回复
热议问题