16 September 2011
Running ASP.NET 4.0 Web Applications on IIS 6

Today, I decided to install a NuGet gallery on our development server at work, in order that we can host our internal packages there, and make them easily available to all projects.  The problem, our development server is not exactly state of the art, and runs Windows Server 2003 SP2 and IIS 6.0.  It did not have ASP.NET 4.0 installed, which is a pre-requisite for the NuGet gallery application.

I was expecting quite a battle to get .Net 4 installed, configured, and working on the server.  My fears were unfounded.  I ran the installer, rebooted, created a virtual directory, set it to ASP.NET version 4.0 (which required an IIS restart, more on this later), published the default "Welcome to ASP.NET" application, and voila!  The result of a HEAD HTTP request to the new virtual directory (note the Server and X-AspNet-Version headers):


The website in action:


It was almost too easy.

So, while I was on a roll, I decided to have a quick play around to find out if it would be easy enough to deploy MVC3 applications to the server.  Unfortunately, it wasn't quite so easy.  I created another virtual directory and set it to .Net 4.  I was surprised that the system prompted me to restart IIS again – I had assumed that this happened before because it was the first app I'd set to version 4.0.  The prompt gives a hint about running aspnet_regiis –norestart –s , but in this case, I didn't know what the virtual path was.

After a little research, I found out that running aspnet_regiis –lk lists the virtual directories on the server, and this is key to getting hold of the magic number that corresponds to the website.  So, with that info, I was able to run:

aspnet_regiis –norestart –s W3SVC/116872853/root/net4mvctest/

which updated my app to .Net 4 without needing an IIS restart.  Note that your virtual directory path will differ from the above!

MVC3 is not installed on the server, and I had no real wish to install it.  To ensure that my app ran on the server, in Visual Studio I selected the menu item "Project –> Add Deployable Dependences…" and ticked "ASP.NET MVC" and "ASP.NET Web Pages with Razor syntax".  Now, I deployed.  The result… "Directory Listing Denied".  Hmmmm.

It turns out that when you deploy a .Net 4 app inside a .Net 2 website, you need to setup a wildcard extension so that .Net handles all requests to the application.  On the application's property pages in IIS Manager, I clicked "Configure" and inserted a new wildcard map to point to C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll and ensured that "Verify that file exists" was unticked.  Ah, that's better…


All in all, it took me less than an hour to set all this up, including working through my problems.  I'd say that was a good hour's work.  Now, I need to get on with configuring and deploying the NuGet gallery…