问题描述
我写了一个程序,它的主机名和站点名称的列表,并把它们作为绑定的网站,如果他们还没有在任何网站上存在。该程序是用.NET 4.0 C#。
本地(IIS 7.5,WIN 7),在code以下的罚款。它可以检测的结合并退出。在我的服务器(IIS 7.0,赢Server 2008中),校验失败,并结合总是添加。是什么给了?
难道LINQ查询是错误的或者是它的Microsoft.Web.Administration库有一些根本性的不足之处处理IIS 7.0?
这里是code,它的部分应的在两台机器上工作:
ServerManager的oIisMgr =新ServerManager的();
网站oSite = oIisMgr.Sites [siteName的]。
字符串sBindInfo =80+ this.StripUrl(主机名);
//看看这种结合已经在一些网站
如果(oIisMgr.Sites
。凡(ST => ST.Bindings.Where(B => B.BindingInformation == sBindInfo)。任何())
。任何())返回true;
结合oBinding = oSite.Bindings.CreateElement();
oBinding.Protocol =HTTP;
oBinding.BindingInformation = sBindInfo;
oSite.Bindings.Add(oBinding);
oIisMgr.CommitChanges();
有关的记录,我发现了什么我的错误了。默认情况下,通过IIS管理控制台,离开添加网站binddings'IP地址:'设置为所有未分配给出这个绑定的字符串:
*:80:some.domain.com
我是在我的code。使用这样的:
:80:some.domain.com//注意失踪通配符
的绑定工作,但任何已通过管理器安装,因为我对查询的主机名绑定信息的通配符少的版本都没有记录为相同的我的LINQ查询。
I've written a program that takes a list of host names and a site name and adds them as bindings to the site if they do not already exist on any site. The program is written in .NET 4.0 C#.
Locally (IIS 7.5, Win 7), the code below works fine. It detects the binding and exits. On my server (IIS 7.0, Win Server 2008), the check fails and the binding is always added. What gives?
Is it that the LINQ query is wrong or is it that the Microsoft.Web.Administration library has some fundamental inadequacy handling IIS 7.0?
Here is part of the code that should work on both machines:
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();
For the record, I found out what my bug was. By default, site binddings added via the IIS Management Console that leave 'IP address:' set to All Unassigned are given this binding string:
"*:80:some.domain.com"
I was using this in my code:
":80:some.domain.com" //note the missing wildcard
The bindings work, but any that had been setup via the manager weren't recorded as identical by my LINQ query since I was querying against the wildcard-less version of the host name binding information.
这篇关于IIS 7.0 VS 7.5网站Microsoft.Web.Administration.Site BindingCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!