UrlRewritingModule w/ Regular Expression Support for ASP.NET 2.0

Here is a really cool URL rewriting module for ASP.NET 2.0.  You can configure it using regular expressions in your web.config file like so:

<urlrewritingnet

  rewriteOnlyVirtualUrls="true"

  contextItemsPrefix="QueryString"

  compileRegex="true"

  xmlns="http://www.urlrewriting.net/schemas/config/2006/01" >

 

  <rewrites>

    <add virtualUrl="^~/(.*)/Detail(.*).aspx"

         rewriteUrlParameter="ExcludeFromClientQueryString"

         destinationUrl="~/Default.aspx?language=$1&amp;id=$2"

         ignoreCase="false"/>

    <add virtualUrl="^~/(.*)/(.*).aspx"

         rewriteUrlParameter="StoreInContextItems"

         destinationUrl="~/$2.aspx?language=$1&amp;parameter=$2&amp;dasistso=schoen"

         ignoreCase="true" />

  </rewrites>

 

</urlrewritingnet>

You can download both the source code and a compiled binary from here.  Very cool and handy!

- Scott

 

Published Wednesday, January 18, 2006 3:34 PM by ScottGu

Comments

# re: UrlRewritingModule w/ Regular Expression Support for ASP.NET 2.0

Thursday, January 19, 2006 2:31 AM by Keyvan Nayyeri
Thank you Scott :)

# re: UrlRewritingModule w/ Regular Expression Support for ASP.NET 2.0

Friday, January 20, 2006 12:24 PM by Brennan Stehling
But can the mappings have arbitrary extensions? I would like to map any path to an ASP.NET handler. The problem I always come across is that IIS does not send those requests into the ASP.NET runtime so the request is never routed through a powerful Url Rewriter like this one.

# re: UrlRewritingModule w/ Regular Expression Support for ASP.NET 2.0

Saturday, January 21, 2006 1:36 PM by scottgu
Hi Brennan,

To have ASP.NET process those requests you'll need to map those extensions to the ASP.NET ISAPI. Note that on IIS6, ASP.NET can then optionally delegate back to the origional ISAPI for the registration. So for example, you should be able to use the URL Rewriter above for classic ASP pages (.asp), and then have classic ASP process the request once you are done.

Hope this helps,

Scott

# re: UrlRewritingModule w/ Regular Expression Support for ASP.NET 2.0

Wednesday, March 7, 2007 5:45 AM by Asbj&#248;rn Ulsberg

Let's hope IIS7 will support arbitrary rewriting in ASP.NET without needing Administrator and GUI access to the server to be able to configure it. Why IIS can't be fully configured in a .config file already is beyond me, but I sincerely hope it will be so in IIS7.

I also hope ASP.NET will include a rewriting framework in a future version, so modules like this isn't necessary. It should all be configurable in a .config file with the option to override stuff programmatically.

Anyway, this is a nice module, so thanks for pointing it out! :-)

PS: Some place in the weblogs.asp.net code base, my name gets borked with ISO-8859-1 or win-1252 conversion. The 'ø' in my name shows up as 'ø' in the "Name" field at least. I guess the cookie handling code isn't working correctly.

# re: UrlRewritingModule w/ Regular Expression Support for ASP.NET 2.0

Wednesday, March 14, 2007 11:08 AM by Shail

Hello Scott,

I am using URl rewrite in my web site, but the pages where I was using Ajax ( Atlas ) are now working as normal pages. What Should I do ?