Asp – How to configure IIS 6.0 to use both default content page and wildcard application maps

asp.netiis

In the filesystem I have

    /file.aspx
    /directory/default.aspx

I want to configure IIS so that it returns the appropriate file (add the aspx extension) or directory (default content page) as follows:

    /file -> /file.aspx
    /directory -> /directory/default.aspx 
    /directory/ -> /directory/default.aspx

I have configured the Wildcard application mapping set to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll. When the "Verify that file exists" is unchecked, the the file request works but not the directory request (returns 404). When the "Verify that file exists" is checked, the directory request works but not the file request.

How can I configure it so that both the file and directory requests will work?

Best Answer

I recommend using UrlRewriter:

http://urlrewriter.net/

This allows you to create all the mappings above that you desire. One thing that you'll have to do (if you're using IIS 6 or earlier) is configure IIS so that all extensions are handled by asp.net. The documentation explains how to do this. Then you create a bunch of rules in your web.config (or separate rewriter.config as I use) in the form of regular expressions to create your mappings.

Incidentally, for the above example, you probably don't need to do anything for the last two rules. IIS will take care of those automatically. For the first rule it will be something like:

<rewrite url="^/file$" to="/file.aspx" />

You could get more clever and write generalized rules so you don't have to write one rule per file.