简体   繁体   中英

Microsoft.Web.Administration Ssl cert not selected in iis manager

I'm playing around with this Microsoft.Web.Administration library to automate deployment of some legacy asp.net webform applications. Everything works except the https binding. The code doesn't give any errors and the site is created with https bindings, only the certificate is not showing as selected in iis manager. Below is the code I used to add the https binding. As you can see in the screenshot it is added, but nothing in the selected dropdown:( I'm running the code on my local machine. I tested with a reference to Microsoft.Web.Administration.dll from my machine (version 7) and one I copied from the server (version 10), not the NuGet package (this doesn't work for reasons).

Any ideas how to get the certificate to be selected in iis?

--Edit-- When running the code locally on the server the cerificate is selected in the iis manager. Code is a little different of course. using (var iis = new ServerManager())...//instead of OpenRemote() and var store = new X509Store(StoreName.My, StoreLocation.LocalMachine); ...//instead of new X509Store(@"\\MyServer\My", StoreLocation.LocalMachine) var store = new X509Store(StoreName.My, StoreLocation.LocalMachine); ...//instead of new X509Store(@"\\MyServer\My", StoreLocation.LocalMachine)

Thx, Bruno

    var store = new X509Store(@"\\MyServer\My", StoreLocation.LocalMachine);
    store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
    var cert = store.Certificates.Cast<X509Certificate2>().FirstOrDefault(c => c.FriendlyName == "WMSVC-SHA2");
    var binding = site.Bindings.CreateElement(); 
    binding.SslFlags = SslFlags.None;
    binding.CertificateHash = cert.GetCertHash();
    binding.CertificateStoreName = store.Name;
    binding.Protocol = "https";                    
    binding.BindingInformation = "*:49102:";                    
    store.Close();
    site.Bindings.Add(binding);

在此处输入图像描述

If you want to see this certificate in IIS, you need to install Microsoft.Web.Administration Ssl cert to your IIS. For specific steps, you can refer to the Manual Intermediate Installation Instructions section in this link .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM