URL Rewrite in asp.net 2.0 (with Regex, Support for Themes and Localisation)

Microsoft has built in a new feature in ASP.NET 2.0, ASP.NET now has a built in URL rewriting support. But since I’m writing an article about it you can probably see that Microsoft stuff is not very useful. Problem with built in URL rewrite is that it lacks regular expression support and without that it is only good for small websites (when I say small I mean it has one index page and another about us page :) ).

URL mapping (rewriting) example:

<urlMappings enabled="true">
<add url="~/Widget/aspx" mappedUrl="~/Products/W/Widgets.aspx"/>

Maybe you wonder why Microsoft didn’t do this properly the way we would have liked it, well it’s basically something that they are doing in IIS7.0 and with that implementation coming soon, it didn’t make sense for the ASP.NET 2.0 team to do a partial implementation that could be subject to security and scalability problems for this release (as said in MS blog). In other words why would you want something like that in IIS6+VS.NET2005 when you have opportunity to spend more money to buy Longhorn server with IIS7.0?

If you go to the link above you will find a free solution for URL rewriting. Most important is that it works with themes and localization. You have to download zip file from their server and copy UrlRewritingNet.UrlRewriter.dll in your bin folder and urlrewritingnet.xsd in xsd folder that you need to create in the root of your application.
And you have to insert some stuff in your web.config file:

<?xml version="1.0"?>
 <section name="urlrewritingnet" restartOnExternalChanges="true" requirePermission ="false" type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter"/>
<urlrewritingnet rewriteOnlyVirtualUrls="true" contextItemsPrefix="QueryString" compileRegex="true" xmlns="http://www.urlrewriting.net/schemas/config/2006/02" >
  <add virtualUrl="^~/(.*)/Detail(.*).aspx" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/Default.aspx?language=$1&amp;id=$2" ignoreCase="true"/>
  <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
 <compilation debug="true" />