Install SSL certificate programmatically using Microsoft.Web.Administration

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

    Adding to Taylor Bird's comment but using powershell:

        ...
    Write-Verbose ("Remove old certificate [ {0} ]... " -f $SiteHttpsBinding.GetAttributeValue("certificateHash"))
    $BindingMethod=$SiteHttpsBindings.Methods["RemoveSslCertificate"]
    $BindingMethodInstance=$BindingMethod.CreateInstance()
    $BindingMethodInstance.Execute()
    Write-Verbose ("Add new certificate [ {0} ]..." -f $AfterThumbprint)
    $BindingMethod=$SiteHttpsBindings.Methods["AddSslCertificate"]
    $BindingMethodInstance=$BindingMethod.CreateInstance()
    $BindingMethodInstance.Input.SetAttributeValue("certificateHash", $AfterThumbprint)
    $BindingMethodInstance.Input.SetAttributeValue("certificateStoreName", "My")
    $BindingMethodInstance.Execute()
    ...
    

    The above code snippet is useful for updating certificates without needing to remove the whole binding. I've used it for adding and updating ssl bindings on local and remote machines.

    Thanks Mr. Bird for supplying the WinAPI reference.

提交回复
热议问题