简体   繁体   English

Microsoft.Web.Administration Ssl 证书未在 iis 管理器中选择

[英]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.我正在使用这个 Microsoft.Web.Administration 库来自动部署一些旧版 asp.net 网络表单应用程序。 Everything works except the https binding.除了 https 绑定外,一切正常。 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.该代码没有给出任何错误,并且该站点是使用 https 绑定创建的,只有证书未显示为在 iis 管理器中选择。 Below is the code I used to add the https binding.下面是我用来添加 https 绑定的代码。 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).正如您在屏幕截图中看到的那样,它已添加,但所选下拉列表中没有任何内容:(我在本地机器上运行代码。我在我的机器(版本 7)中参考 Microsoft.Web.Administration.dll 进行了测试还有一个我从服务器(版本 10)复制的,而不是 NuGet package (这不起作用)。

Any ideas how to get the certificate to be selected in iis?任何想法如何获得在 iis 中选择的证书?

--Edit-- When running the code locally on the server the cerificate is selected in the iis manager. --编辑-- 在服务器上本地运行代码时,在 iis 管理器中选择证书。 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) using (var iis = new ServerManager())...//instead of OpenRemote()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.如果你想在 IIS 中看到这个证书,你需要安装 Microsoft.Web.Administration Ssl 证书到你的 Z54EFB7DA5ACF466EB61 For specific steps, you can refer to the Manual Intermediate Installation Instructions section in this link .具体步骤可以参考此链接中的手动中间安装说明部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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