【问题标题】:Set website port with ServerManager class使用 ServerManager 类设置网站端口
【发布时间】:2012-07-21 22:18:18
【问题描述】:

我需要帮助使用 Microsoft.Web.Administration.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);

【问题讨论】:

标签: c# iis-7


【解决方案1】:

您是否提交更改?

这是我在服务器管理应用程序中的代码(根据 Xml 文档中的数据创建):

ServerManager manager = new ServerManager();
Site site = manager.Sites[siteName];

foreach (XElement bindingNode in bindingsNode.Elements("Binding")) {
    Binding binding = site.Bindings.CreateElement();
    binding.BindingInformation = String.Format("{2}:{0}:{1}", bindingNode.Attribute("Port").Value, bindingNode.Value, bindingNode.Attribute("IP").Value);
    site.Bindings.Add(binding);
}

manager.CommitChanges();

【讨论】:

  • 你试过我的方法了吗?通过设置 BindingInformation? "127.0.0.1:8080:domain.com" ?
  • 是的,我得到了 COMException。
  • 好的,那么问题肯定出在其他问题上。您正在使用哪些版本? IIS 和 .NET?
  • IIS 7 和 .NET4 也不是客户端配置文件,我作为 64 位应用程序运行。
  • 对不起,不知道!然后只剩下一个权限,“以管理员身份运行”?除此之外,不知道!
猜你喜欢
  • 2013-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-20
  • 2014-07-29
  • 2013-10-07
相关资源
最近更新 更多