IIS 7.0 vs 7.5 Site Microsoft.Web.Administration.Site BindingCollection

十年热恋 提交于 2019-12-10 14:29:52

问题


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

回答1:


For the record, I found out what my bug was. By default, site bindings 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.



来源:https://stackoverflow.com/questions/5121383/iis-7-0-vs-7-5-site-microsoft-web-administration-site-bindingcollection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!