我需要使用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