Add bindings to a website (quickly)

As you know, IIS 7 is a powerful webserver. Just last month, after only three months of development time, we deployed the new website http://www.beurs.nl/ on an IIS 7 platform (with SQL Server 2008 back end).

This site, with over 7 mln pageviews/months, was built using ASP.NET MVC and Entitity Framework. A technology decision we haven't regretted. One advantage of ASP.NET MVC was the relative ease to support old urls that were still in use by other websites, and search engines. This meant that a url like http://www.beurs.nl/frame2.php still works. Sure, you can do that with simple URL rewriting, but obviously there are other advantages to using ASP.NET MVC. The webservers (three, load balanced) also run other sites, such as one for creating charts and another for the back-end CMS.

When figuring out which legacy urls to support, we found that the previous site had multiple aliases, such as koersen.beurs.nl, koersen3.beurs.nl, ticker.beurs.nl, etc. If we had a dedicated ip address for the primary site, and seperate ones for the other sites on the server, we could simply use a wildcard for all hostheaders. But… we do not. As a result, we needed to add each hostheader individually. The way to do this is described in this post. Though not difficult, it's quite a pain to do for 15 hostheaders, on three webservers. Yes, it's possible to share IIS 7 configuration, but we preferred not to. We do use DFS to mirror the website-folders.

As it turns out, it's not too difficult to add these binding from the command prompt:

c:\Windows\system32\inetsrv\appcmd.exe set site /site.name: www.beurs.nl /+bindings.[protocol='http',bindingInformation='*:80:forum.beurs.nl']
c:\Windows\system32\inetsrv\appcmd.exe set site /site.name:
www.beurs.nl /+bindings.[protocol='http',bindingInformation='*:80:grafieken.beurs.nl']
c:\Windows\system32\inetsrv\appcmd.exe set site /site.name:
www.beurs.nl /+bindings.[protocol='http',bindingInformation='*:80:koersen.beurs.nl']

etc


A simple script that takes 30 seconds to make and 2 seconds to run. AppCmd.exe is the single command line tool for managing IIS 7.0  that every developer/it pro should know.