我编写了一个程序,它获取一个主机名列表和一个站点名称,如果它们不存在于任何站点上,则将它们作为绑定(bind)添加到该站点。该程序是用 .NET 4.0 C# 编写的。
在本地(IIS 7.5、Win 7),下面的代码工作正常。它检测绑定(bind)并退出。在我的服务器(IIS 7.0,Win Server 2008)上,检查失败,总是添加绑定(bind)。给了什么?
是 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();
最佳答案
郑重声明,我发现了我的错误是什么。默认情况下,通过 IIS 管理控制台添加的将“IP 地址:”设置为 所有未分配 的站点绑定(bind)将获得此绑定(bind)字符串:
"*:80:some.domain.com"
我在我的代码中使用了这个:
":80:some.domain.com"//注意缺少的通配符
绑定(bind)有效,但我的 LINQ 查询没有将任何通过管理器设置的绑定(bind)记录为相同,因为我查询的是主机名绑定(bind)信息的无通配符版本。
关于c# - IIS 7.0 与 7.5 站点 Microsoft.Web.Administration.Site BindingCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5121383/