Install SSL certificate programmatically using Microsoft.Web.Administration

前端 未结 7 1750
执念已碎
执念已碎 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:42

    The namespace doesn't contain an API for this, so you have to use its ConfigurationMethod to invoke an extension to the Win API that performs this function. Something like:

    string certificateHash = 
    string certificateStore =   #my, localmachine, etc
    
    ConfigurationMethod method = binding.Methods["AddSslCertificate"];
    ConfigurationMethodInstance mi = method.CreateInstance();
    mi.Input.SetAttributeValue("certificateHash", certificateHash);
    mi.Input.SetAttributeValue("certificateStoreName", certificateStore);
    mi.Execute();
    

提交回复
热议问题