2011-02-25 60 views
5

我已经编写了一个程序,它接受主机名和网站名称列表,并将它们作为绑定添加到网站(如果它们不存在于任何网站上) 。该程序是用.NET 4.0 C#编写的。IIS 7.0 vs 7.5网站Microsoft.Web.Administration.Site BindingCollection

本地(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(); 

回答

7

为了记录在案,我发现了什么我的错误了。默认情况下,通过IIS管理控制台,离开添加站点绑定的IP地址:'设置为全部未分配给出此绑定的字符串:

“*:80:some.domain.com”

“:80:some.domain.com”在我的代码使用这个//注意失踪通配符

的绑定工作,但通过经理任何已经安装并没有记录相同通过我的LINQ查询,因为我查询的是主机名绑定信息的无通配符版本。