URL Rewrite for virtual paths

Most .NET examples for URL rewriting use HTTPModules or HTTPHandlers rather than actual ISAPI filters. (Yes, there is still a diffrence.)

The big problem with this is the fact that the URL calls for the rewrites have to trigger a .NET call to the ASP.NET ISAPI filter to even have your HTTPModule or HTTPHandler to be launched.

That means that your URL file extension needs to be .aspx, .asmx, .asax, .ascx, .ashx, .axd. But what if you want a redirect based on .gif, .swf, .xml? Sorry you are out of luck. But not realy.

If your rewrite code is generic enough, you can rewrite these too by telling IIS to use the ASP.NET Isapi filter on these files.

Step by step below:

  1. From IIS console, go to your application directory and open the properties window.
  2. Go to the “Home Directory” tab
  3. Click on “Configuration” Button
  4. On the “Mappings” tab you will set your Isapi filters.
  5. We will now map SWF to the ASP.NET Isapi filter.
  6. Click Add
  7. Enter “c:\winnt\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll” into the executable path. (This is for the 2.0 framework.)
  8. Type your extension like “.swf”. No leading wild cards. Do not forget to put in the leading period before the actual extension.
  9. Leave script engine checked.
  10. Uncheck “Verify if file exists”
  11. As a minimum, verb should be get, but with static items, I may put all, and use the rewriter to block writes. Then I can control posting by user rights.

That is it. It only took me too many hours in one day to discover all of this.

Note: This was ASP.NET 2.0 and IIS 6.0. I have not tried this on the 3.0 framework or on any pre-releases of the IIS 7.0.

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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.