我需要使用Microsoft.Web.Administration.ServerManager類爲網站設置端口的幫助。使用ServerManager類設置網站端口
首先,我得到的網站:
Site site = this._serverManager.Sites[section.WebsiteName];
然後我嘗試設置從我的設置,我傳遞的端口:
foreach (Binding b in from binding in site.Bindings.Where(b => b != null && b.EndPoint != null)
select binding)
{
b.EndPoint.Port = Int32.Parse(section.Port);
Console.WriteLine(b.EndPoint.Port);
} this._serverManager.CommitChanges();
我把的WriteLine在那裏檢查和端口將不再得到改變爲什麼?我已經知道這個網站是有效的,因爲在我到達這裏之前我會檢查一下。
Binding binding = site.Bindings.CreateElement();
binding.BindingInformation = String.Format("{2}:{0}:{1}", section.Port,b.Host, b.EndPoint.Address);
//b.EndPoint.Port = Int32.Parse(section.Port);
site.Bindings.Add(binding);
我想,上面我也得到一個關於GetAttributeValue收到COMException。
終於得到它感謝回答以下我不得不這樣做:
b.BindingInformation = String.Format("{2}:{0}:{1}", section.Port, b.Host, b.EndPoint.Address);
包含更多信息的一個類似的問題是提供[#1本身] [1] [1]:http://stackoverflow.com/questions/6101712/change-http-port-for-default-web-site# – Vin 2015-07-10 22:56:15