Matthew Cox Team : Web Development Tags : Web Development Programming

IIS7

Matthew Cox Team : Web Development Tags : Web Development Programming

When I am developing web sites, I like my development environment to match, as closely as possible, the actual live environment on the server that will host the finished site. For this reason I prefer to use IIS for development and testing, over the inbuilt development server included with Visual Studio. Having recently upgraded my development pc to Windows Vista I found that one of the essential little tools that I use every day no longer worked, I’m referring to IIS Admin, a badly written little hack of an application that for all its VB6 nastiness I have come to rely on. This application is simply a tray icon that when clicked would simply list all the entries in IIS and allow you to switch between them with a click of a button.

So I was left with a few options: Firstly just manually switch between entries. I tried this one, it got old after about five minutes. Secondly; find another piece of software to replace it. I probably could have accomplished this one, but didn’t want to trawl through software sites filled with spyware and nagware. Thirdly, build it myself. If I’m going to be running a dodgy hack of an app, at least it will be my dodgy hack of an app.

Developing this application was astoundingly easy, all thanks to Microsoft.Web.Administration.dll (WMA to satisfy Microsoft’s acronym fixation). With IIS 7 Microsoft has created a new managed library that allows complete programmatic control of IIS. For my purposes this was as simple as declare an instance of the Server Manager class.

ServerManager manager = new ServerManager();

From there you have access to a collection of Site objects that represent every entry in IIS.

manager.Sites;


And starting or stopping a site is as easy as calling site.Start(); or site.Stop();

So with nothing more than a couple of hours tinkering I now have a simple application that saves a lot of time when jumping from project to project. One caveat though, access to IIS requires administrator privileges, so don’t forget to add <requestedExecutionLevel level="requireAdministrator" />  to the application manifest file.