Ensuring that IIS 7 will handle extensionless URLs

As you probably know, I’ve been updating my ASP.NET book to 4.0. It has been more work that initially expected, but I can also say that I’ve been having some fun. One of the things I’ve had to investigate was routing. This is one of those cool additions that will really help improve SEO in web forms apps (ASP.NET had some support for friendly URLs, but it was close to useless :),,)

Now, if you’ve been doing MVC, you already know that routes are an important feature and you probably know lots about it (btw, I’ve written about it in the past). One of the things you probably know is that getting extensionless URLs in IIS 6 involves some configuration. However, that shouldn’t be needed in IIS 7 and above. I guess it was a surprise to me when I started getting 404 on my demo app for routing in Web Forms. What? 404? But I’m running the site in IIS 7 with integrated mode on…wtf???

Well, after some tweaking, I’ve managed to understand what was going on: you must ensure that the routing module is configured to handle managed and unmanaged requests (there are several options for doing this; the easiest is using the IIS 7 admin console – check the properties of a module and you should see a dialog with a checkbox that lets you enable/disable this feature).

I’ve started asking around and I was lucky enough to get an answer from Stefan Schackow about it. When you create a new VS project, you’ll see that the web.config contains the following entry:

<modules runAllManagedModulesForAllRequests="true" />

this is all that takes to make everything run smoothly. Unfortunately, I’ve ended up deleting that entry from the web.config and that meant that my extensionless URL never got through the URL module (it ended up being processed by the static file handler, which is not a managed handler). Special thanks go to Stefan for helping me with this problem.


~ by Luis Abreu on December 9, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: