URL mapping in ASP.NET

I had a requirement from our SEO department for a website. They wanted to create some static URL sort of pages for a website they were working on and wanted those URLs to be placed on the website footer.

Now, the pages they required were similar to the pages that already existed on the website. For e.g. they wanted a page like /name1_name2.aspx where as it already existed in the format as /results_page.aspx?q1=name1&q2=name2.

They wanted a URL which did not have any strings (query string :)) attached to it.

Now I could have created separate pages and then used the same classes on the new pages as on the results page but I had a better idea. I knew ASP.NET provided some sort of url mapping feature through the web.config. So after some research I found it.

If you place the following code in the system.web section of your web.config you will achieve url mapping.

<urlMappings enabled="true">   
<add url="~/name1_name2.aspx" mappedUrl="~/results_page.aspx?q1=name1&q2=name2" />   

If you run the some_page.aspx it will in actuality run the results_page.aspx without the visitor ever noticing. So, I just have to add as many entries as I want in the web.config file and voila it starts working.

Please note if you have a large number of files to map then please use URL Rewriting in ASP.NET than this.

Hope this helped you

Leave a Comment