When to Use URL Mapping in ASP.NET
I saw a question on the ASP.NET forums on when to use or what is URL Mapping good for. This is a very good question, especially for newbies to the ASP.NET paradigm.
URL Mapping is nice when you have a legacy site you are upgrading to ASP.NET for example. I would not recommend it for a really large site. A typical small business site of 4-10 pages it is perfect. So you inherit an old HTML site from a new client, you need to map the old URLs to the new URLs so you will not loose any search engine love or cause people's bookmarks to be broken.
URLMapping handles the redirection for you and makes it easy to do. the problem is when you start getting a lot of URLs in the map you will see a performance degradation. In this case you should go to URL Rewriting to handle the mapping of the pages. In the scenario I described above you would also want to send a 301 status code so the search engines know how to apply the update pages and the rankings are preserved.
To implement URL Mapping you would setup the urlMappings element in the system.web element of the web.config file. Inside the urlMappings element each mapping would be added as a child element. The add element has two attributes that need to be added, url and mappedurl. The url attribute is the old URL and the mappedurl is the new URL.
<urlMappings><addurl="~/index.htm"mappedUrl="~/default.aspx"/><addurl="~/Contact%20Us.htm"mappedUrl="~/contact.aspx"/><addurl="~/Contact Us.htm"mappedUrl="~/contact.aspx"/><addurl="~/Community.htm"mappedUrl="~/content.aspx?PageName=Community"/><addurl="~/Careers.htm"mappedUrl="~/content.aspx?PageName=Careers"/><addurl="~/residential.htm"mappedUrl="~/content.aspx?PageName=residential"/><addurl="~/small_business.htm"mappedUrl="~/content.aspx?PageName=business"/><addurl="~/new_construction.htm"mappedUrl="~/content.aspx?PageName=construction"/><addurl="~/renters.htm"mappedUrl="~/content.aspx?PageName=renters"/></urlMappings>
Notice how the URLs can be mapped using the ~ to specify the root. This makes it pretty easy to keep things mapped regardless of the actual domain being used on the site.
I like URL Mapping as an easy URL Rewriting mechanism for small site upgrades or a quick fix to a site that is changing. For anything larger than a few pages I work out a viable URL Rewriting strategy using the RewritePath method.