IIS 7.0与7.5站点Microsoft.Web.Administration.Site BindingCollection

for*_*reh 5 .net c# linq iis-7 iis-7.5

我编写了一个程序,它接受一个主机名列表和一个站点名称,如果它们在任何站点上都不存在,则将它们作为绑定添加到站点.该程序是用.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();
Run Code Online (Sandbox Code Playgroud)

for*_*reh 7

为了记录,我发现了我的错误.默认情况下,通过IIS管理控制台添加的"IP地址:"设置为" 全部未分配 "的站点绑定将被赋予此绑定字符串:

"*:80:some.domain.com"

我在我的代码中使用它:

":80:some.domain.com"//注意丢失的通配符

绑定工作,但任何通过管理器设置的都没有被我的LINQ查询记录为相同,因为我查询了主机名绑定信息的无通配符版本.