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 > <add url="~/index.htm" mappedUrl="~/default.aspx"/> <add url="~/Contact%20Us.htm" mappedUrl="~/contact.aspx"/> <add url="~/Contact Us.htm" mappedUrl="~/contact.aspx"/> <add url="~/Community.htm" mappedUrl="~/content.aspx?PageName=Community"/> <add url="~/Careers.htm" mappedUrl="~/content.aspx?PageName=Careers"/> <add url="~/residential.htm" mappedUrl="~/content.aspx?PageName=residential"/> <add url="~/small_business.htm" mappedUrl="~/content.aspx?PageName=business"/> <add url="~/new_construction.htm" mappedUrl="~/content.aspx?PageName=construction"/> <add url="~/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.