簡體   English   中英

Microsoft.Web.Administration Ssl 證書未在 iis 管理器中選擇

[英]Microsoft.Web.Administration Ssl cert not selected in iis manager

我正在使用這個 Microsoft.Web.Administration 庫來自動部署一些舊版 asp.net 網絡表單應用程序。 除了 https 綁定外,一切正常。 該代碼沒有給出任何錯誤,並且該站點是使用 https 綁定創建的,只有證書未顯示為在 iis 管理器中選擇。 下面是我用來添加 https 綁定的代碼。 正如您在屏幕截圖中看到的那樣,它已添加,但所選下拉列表中沒有任何內容:(我在本地機器上運行代碼。我在我的機器(版本 7)中參考 Microsoft.Web.Administration.dll 進行了測試還有一個我從服務器(版本 10)復制的,而不是 NuGet package (這不起作用)。

任何想法如何獲得在 iis 中選擇的證書?

--編輯-- 在服務器上本地運行代碼時,在 iis 管理器中選擇證書。 代碼當然有點不同。 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)

謝謝,布魯諾

    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);

在此處輸入圖像描述

如果你想在 IIS 中看到這個證書,你需要安裝 Microsoft.Web.Administration Ssl 證書到你的 Z54EFB7DA5ACF466EB61 具體步驟可以參考此鏈接中的手動中間安裝說明部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM