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

 

5 Comments

  • Thank you Scott :)

  • 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.

  • 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

  • Let&#39;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&#39;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&#39;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 &#39;&oslash;&#39; in my name shows up as &#39;&Atilde;&cedil;&#39; in the &quot;Name&quot; field at least. I guess the cookie handling code isn&#39;t working correctly.

  • 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 ?

Comments have been disabled for this content.