Published: 18 Jun 2010
By: Manning Publications

This article is taken from the book ASP.NET MVC 2 in Action. The authors discuss URL rewriting as a powerful deployment option that opens up new scenarios in URL canonicalization and seamless resource management.

About the book

This is the sixth chapter of the book ASP.NET MVC in Action. It has been published with the exclusive permission of Manning.

Written by: Jeffrey Palermo, Ben Scheirman, Jimmy Bogard, Eric Hexter, and Matthew Hinze
Pages: 432
Publisher: Manning
ISBN-10: 9781935182795
Get 30% discount

DotNetSlacker readers can get 30% off the full print book or ebook at using the promo code dns30 at checkout.

When we deploy our MVC application to Internet Information Services (IIS) 6 and earlier, we can consider a few options concerning routes. IIS 6 and earlier use Internet Server Application Programming Interface (ISAPI) filters, which map file extension requests to ISAPI handlers. Extensions, such as .aspx and .ascx, map to the ASP.NET ISAPI handler, but extensions in the pretty, extension-less MVC URLs do not. By the time ASP.NET handles the request, IIS has already chosen an ISAPI handler for the request, and the selection may not be ASP.NET. Unfortunately, developing custom ISAPI filters requires C/C++ knowledge. Although some open source projects exist for writing managed ISAPI filters, it is not as easy as creating a custom IHttpHandler or IHttpModule implementation.

Out of the box, ASP.NET MVC applications will not work in IIS 6. Getting an MVC application to run successfully in an IIS 6 environment requires either changes to our routes or extra configuration steps in IIS. Our four choices for deploying to IIS 6 are:

  • Configure routes to use the .aspx extension
  • Configure routes to use a custom extension (such as .mvc)
  • Use a wildcard mapping with selective disabling
  • Use URL rewriting

In this article, we will focus on custom extensions.

Instead of mapping our routes to the .aspx extension, a custom extension could reduce the confusion of users accustomed to Web Forms URLs. We’ll configure our routes to use the .mvc extension instead of .aspx, as seen in listing 1.

Listing 1: Route configuration using the custom .mvc extension

This configuration differs from the previous .aspx route configuration in the extension only. When it comes to deploying this route configuration, we need to perform additional steps in IIS. Since IIS is not configured to handle requests from the .mvc extension, we’ll need to add a mapping that will enable the ASP.NET ISAPI filter to handle the .mvc extension. To map the new extension, follow the listed steps as shown in figures 1 and 2:

  1. Create the website with the default configuration.
  2. In the Home Directory tab in the Properties dialog for the website, click Configuration...
  3. Website properties dialog
  4. In the Mappings tab in the Application Configuration dialog, click Add….
  5. In the Add/Edit Application Extension Mapping dialog, set the Executable value to the path to the aspnet_isapi.dll. This is typically at C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll. Use the .NET 2.0 version of the dll.
  6. Set the Extension value to .mvc. Make sure the extension has the leading dot.
  7. Select All verbs in the Verbs section. If you know the HTTP verbs you wish to support, provide a commaseparated list of the verbs in the Limit to section.
  8. Uncheck the Verify that file exists option. The requested URLs will not map to a location on disk, and IIS responds with a 404 if you don’t uncheck this value.
  9. Configuration values for the new .MVC IIS extension mapping
  10. Click OK on all of the configuration dialogs.

Now that we have configured IIS to allow ASP.NET to handle requests for the .mvc extension, we can use the MVC application. Our new URL is http://localhost:82/product.mvc/show/4, which is only a slight cosmetic change from http://localhost:81/product.aspx/show/4—the original extension.


With the new routing abilities of ASP.NET MVC, came new deployment challenges. Although IIS 7 supports extension-less, pretty URLs out of the box, earlier versions of IIS do not. However, we have a variety of deployment options with earlier versions of IIS, some of which enable pretty URLs. URL rewriting is the most powerful of these deployment options because it opens up new scenarios in URL canonicalization and seamless resource management.

Get 30% discount

DotNetSlacker readers can get 30% off the full print book or ebook at using the promo code dns30 at checkout.

<<  Previous Article Continue reading and see our next or previous articles Next Article >>

About Manning Publications

Manning Publication publishes computer books for professionals--programmers, system administrators, designers, architects, managers and others. Our focus is on computing titles at professional levels. We care about the quality of our books. We work with our authors to coax out of them the best writi...

This author has published 33 articles on DotNetSlackers. View other articles or the complete profile here.

Other articles in this category

Code First Approach using Entity Framework 4.1, Inversion of Control, Unity Framework, Repository and Unit of Work Patterns, and MVC3 Razor View
A detailed introduction about the code first approach using Entity Framework 4.1, Inversion of Contr...
Exception Handling and .Net (A practical approach)
Error Handling has always been crucial for an application in a number of ways. It may affect the exe...
jQuery Mobile ListView
In this article, we're going to look at what JQuery Mobile uses to represent lists, and how capable ...
Book Review: SignalR: Real-time Application Development
A book review of SignalR by Simone.
JQuery Mobile Widgets Overview
An overview of widgets in jQuery Mobile.

You might also be interested in the following related blog posts

A RouteHandler for IHttpHandlers read more
MVC or Web Forms? A Dying Question read more
Designer Support for One-Way navigations in Entity Framework 4 read more
How To: Silverlight grid hierarchy load on demand using MVVM and RIA services read more
SharePoint 2010 Workflow read more
ASP.NET MVC2 Preview 2: Areas and Routes read more
Creating a Filtering User Interface With jQuery In a Web Forms Application: Part 1 read more
Lower Case URLs and ASP.NET MVC read more
Free software for you! WebsiteSpark let the mountain go to Microsoft instead. read more
An alternative to Crystal read more

Please login to rate or to leave a comment.