Datasheet

Using the ASP.NET v2.0 URL Mapping feature appears to be a great capability, but there is one catch:
You can’t use regular expressions. The articles example in this section could have been better written
using regular expressions. Notice that the
urlMappings elements contain very similar code that only
differs by year or month. This could have been implemented better with a single regular expression that
mapped the year and month with parameter placement. If you used Scott Mitchell’s URL rewriting
engine, the configuration would look like this:
<RewriterConfig>
<Rules>
<!-- Rules for Blog Content Displayer -->
<RewriterRule>
<LookFor>~/(\d{4})/(\d{2})/Default\.aspx</LookFor>
<SendTo><![CDATA[~/YearView.aspx?year=$1&month=$2]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/(\d{4})/Default\.aspx</LookFor>
<SendTo>~/YearView.aspx?year=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
This is a simple, one-time configuration. However, with the Visual Studio 2005 implementation, demon-
strated by the
urlMapping elements of the configuration file in Listing 1-9, you must continually update
the file for every year and every month of every year. This is not practical because the file will continually
grow and it requires manual intervention. For serious URL rewriting capabilities with regular expressions,
I recommend you use the hack in Scott Mitchell’s article. Use the URL mapping feature of ASP.NET v2.0 in
only the simplest cases.
Wrapping Up
This chapter introduced a few hacks that were invented by pioneers of ASP.NET v1.1. These people and
others had such a great influence that Microsoft turned their hacks into major product features in
ASP.NET v2.0. Wizard hacks became the Wizard control. Template, inheritance, and user control Master
Page hacks became Master Pages in ASP.NET v2.0. URL rewriting hacks influenced URL mapping in
ASP.NET v2.0, and are still so good that the URL rewriting hacks will continue to be a preferred method
of implementing URL rewriting when regular expressions are desired.
24
Chapter 1
04_597663 ch01.qxp 4/25/06 9:54 PM Page 24