【发布时间】:2011-02-25 18:55:19
【问题描述】:
我编写了一个程序,它获取主机名列表和站点名称,如果它们在任何站点上尚不存在,则将它们作为绑定添加到站点。该程序是用 .NET 4.0 C# 编写的。
本地(IIS 7.5,Win 7),下面的代码工作正常。它检测到绑定并退出。在我的服务器(IIS 7.0、Win Server 2008)上,检查失败并且总是添加绑定。什么给了?
是 LINQ 查询错误还是 Microsoft.Web.Administration 库在处理 IIS 7.0 时存在一些根本性的不足?
这是应该在两台机器上都可以工作的部分代码:
ServerManager oIisMgr = new ServerManager();
Site oSite = oIisMgr.Sites[siteName];
string sBindInfo = ":80:" + this.StripUrl(hostName);
//See if this binding is already on some site
if (oIisMgr.Sites
.Where(ST => ST.Bindings.Where(B => B.BindingInformation == sBindInfo).Any())
.Any()) return true;
Binding oBinding = oSite.Bindings.CreateElement();
oBinding.Protocol = "http";
oBinding.BindingInformation = sBindInfo;
oSite.Bindings.Add(oBinding);
oIisMgr.CommitChanges();
【问题讨论】:
标签: c# .net linq iis-7 iis-7.5