Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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();
like image 558
fordareh Avatar asked Feb 25 '11 18:02

fordareh


People also ask

What are site bindings IIS?

Binding a certificate to a website in IIS means that you are activating the installed digital certificate and associating it with a particular website, port, and/or IP Address.

What is MWA Microsoft?

The Microsoft. Web. Administration (MWA) APIs are built as a managed code wrapper over the Application Host Administration API (AHADMIN) which is a native code interface library. It provides a programmatic way to access and update the web server configuration and administration information.


1 Answers

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.

like image 130
fordareh Avatar answered Sep 19 '22 22:09

fordareh