Last night I was on the hunt for a new Url ReWriting Solution for my ASP.NET 2.0 websites, because my host provider of choice has decided to run ASP.NET 2.0 Shared Host Accounts in a partial-trust environment that has made my chosen URL ReWriting technique of using PageParser.GetCompiledPageInstance unusable - it throws a security exception in a partial-trust environment.
URLMapping in ASP.NET 2.0
With ASP.NET 2.0, Microsoft has provided a simple, but limited solution for those developers looking for Url ReWriting on their websites. Web.config has a new Configuration Section, called urlMappings that allows you to map an incoming url to a mappedUrl where you would like the request to go:
<urlMappings>
<add url="~/category/toothpicks.aspx"
mappedUrl="~/displaycategory.aspx?Category=1"/>
<add url="~/category/drinkumbrellas.aspx"
mappedUrl="~/displaycategory.aspx?Category=2"/>
<add url="~/category/fancypants.aspx"
mappedUrl="~/displaycategory.aspx?Category=3"/>
</urlMappings>
Hence, a request going to the toothpicks.aspx page as mentioned in the first rewrite rule above will actually be routed to displaycategory.aspx?Category=1. Very cool.
What about Regular Expressions ?
So this is cool and all, but for larger sites that are more dynamic in nature and content is created on the fly, nobody wants to be adding mappings manually into Web.config. That would be a maintenance nightmare.
This begs the question, how about using regular expressions?
Unfortunately, the current version of Url Mapping in ASP.NET 2.0 does not support regular expressions. Yeah, I agree, not supporting regular expressions pretty much defeats the purpose of the feature. Scott Guthrie talks about why the current version of Url Mapping doesn't support regular expressions here. I understand it, but it sure disappoints me.
To Be Continued...
Source: David Hayden ( .NET Developer )