Archive for October, 2011

Getting MVC 4 running on Server 2003

October 24, 2011

For many of us, just updating to the latest Server software isn’t in all cases an option.

Make sure .NET 4.0 is installed.

The most reliable way to check the .NET framework and service pack versions is to consult the registry.
This is a good table that will tell you this.
If you find .NET 4.0 isn’t installed, you’ll have to download and install it.

Make sure ASP.NET 4.0 is activated for your web site

First you’ll need your web sites SiteID.
Open IIS Manager.
Click the Web Sites folder in the left pane. In the right pane, you’ll see all your web sites listed.
There should be a column called “Identifier”. The fields beneath are the web sites SiteID’s.
Take note of your web sites Id.

Navigate to ASP.NET’s default path C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319
You’ll then need to run the following command:

aspnet_regiis -lk | find "Id"

Where “Id” is your web sites Id as you recorded above.
You need the quotes too.

This should produce the following:

"W3SVC/Id/ROOT/ [your .NET framework version number]"

That’s what your website’s virtual path in IIS6.0 looks like with the .NET framework version tacked on the end, without the quotes.
Id of course will be your web sites Id.

If the .NET framework version isn’t v4.0.30319, you’ll need to register it.
Run the following command:

aspnet_regiis.exe -norestart -s "W3SVC/Id/ROOT/"

Id is once again your web sites Id.
This should register ASP.NET 4.0 with your web site.
IIS won’t need restarting.

Make sure the App pool your web site is going to run in is dedicated to .NET 4.0

Here’s some doc for aspnet_regiis.exe

Make sure ASP.NET MVC 4 is installed on the target machine

or the project is set to bin deploy
I prefer to bin deploy, so we don’t clutter up the old server.
Any additional libraries I need,
I include by using NuGet at solution level,
This allows many projects to use the same packages.

It looked like after some research,
but before I actually started on this,
that we would run into this problem, but no,
It turned out that our .NET 4 ASP.NET ISAPI extension was already enabled.

File extension mapping

The file extension in the URL (.aspx for example) must be mapped to aspnet_isapi.dll.
If it is, and there’s a .aspx in the URL,
aspnet_isapi.dll invokes ASP.NET.
If ASP.NET is invoked, (because UrlRoutingModule is a .NET IHttpModule) UrlRoutingModule gets invoked.

IIS 6 only invokes ASP.NET when it sees a “filename extension” in the URL that’s mapped to aspnet_isapi.dll
This means we have to do some work to get IIS 6 to recognise files that don’t have this mapping.
As this was a test deployment, I wasn’t too concerned about speed.
So decided to use wildcard mapping for aspnet_isapi.dll, as it was the easiest to setup.

Open IIS Manager

1. Right click on your web app and select Properties
2. Select the HomeDirectory tab
3. Click on Configuration

4. Under the Wildcard application maps edit box,
—-click Insert (not Add)
5. Enter C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319
—-\aspnet_isapi.dll for the “Executable:”
6. Uncheck “Verify that file exists”

7. Click OK, OK

There are a few ways of achieving a similar result.
Here are some ideas:

http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
http://blog.stevensanderson.com/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/
Another resource that’s well worth a read is the “Test Drive ASP.NET MVC” book.
In chapter 12 it talks a little about this also in the section… IIS 6.0 on Windows Server 2003 or XP Pro x64

Multiple ASP.NET sites on same port

October 23, 2011

How to get multiple ASP.NET web sites running on a single machine using the same default port.

Say I have myfirstsite, mysecondsite

Open your hosts file as administrator (UAC will only let you do this as admin).
On the machine I’m using (Windows 7) it’s C:\windows\system32\drivers\etc\hosts
Add the following lines:

127.0.0.1 myfirstsite
127.0.0.1 mysecondsite

In IIS for both myfirstsite and mysecondsite,
you’ll need to make sure the bindings bind to all IP addresses on port 80.
The HostName will probably need to be changed to the name of your website

In IIS 7 / 7.5 To add a host header entry for a Web Site in IIS 7 / 7.5

  1.     Right click the Web Site.
  2.     Click Edit Bindings…

  1.     Click on http and click Edit…

  1.     Type the host header in the text box “Host name:” and click OK.

If you still have the great joy of working with IIS 6.0

  1.     Right click Web Site
  2.     Click on Properties.
  3.     Click Advanced… button in the Web Site tab
  4.     Click on Default and click Edit…
  5.     Type the host header in the text box “Host Header value:”

You should now be able to browse to http://myfirstsite and also http://mysecondsite using the default port 80