IIS issues with UrlRewriter.Net

Trying to build an ASP.Net application using UrlRewriter.Net for some of the pages, as sketched by this blog entry of ScottGu.

The rewriting generally works based on these rules:

  <rewrite url="^~/text/(.+)$" to="~/text.aspx?title=${encode($1)}" />
  <rewrite url="^~/text/$" to="~/default.aspx" />
  <rewrite url="^~/text$" to="~/default.aspx" />

but there are some issues, which are probably caused by IIS (IIS 7 on Windows 7 in this case) rather than the rewriting module.

The configuration above redirects any request to the /text/ directory to the test.aspx Web Page.

First lesson learned: if you expect “funny” characters in the URL parameter (i.e. everything that needs to get URL-encoded), use the encode transformation.

Second, ASP.Net somehow loses track of what the “real” current URL directory is, so the “~/” (application root path) may not evaluate as expected. Use ResolveUrl() in pages that are affected by a rewrite module.

Two mysteries remain, though:

  • a final dot in the URL causes a 404
  • a sequence of two dots in the URL causes a 400

If you follow the MS links on a related Stack Overflow question, you will find that they are aware of similar problems for about 2 years, with the issues still unresolved.

The best strategy seems to be to avoid generating these kind of URLs in the first place.

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: