Posts

Showing posts from September 19, 2010

ASP.NET 4.0 Feature - URL Routing

Image
Let’s see the new feature in ASP.NET 4.0 known as “URL Routing”. URL Routing is a feature which is driven by the ASP.NET URL routing engine which enables the application to route to custom urls instead of actual urls which may have some querystrings etc. In the past we have seen urls like http://localhost/NewStore/Titles.aspx can be now show as http://localhost/NewStore/AllTitles or http://localhost/NewStore/Titles.aspx?ID=2 can be now shown as http://localhost/NewStore/Products/Fiction . Doesn’t this look great? Now let’s see how do we achieve this. We would be using the “System.Web.Routing” class which products us a method “MapPageRoute” which helps to do the routing. Let us see a simple example where we would have two pages one which shows All the Titles and another which shows Title for a specific Author Id. For this example I am using the Pubs Database. We would have to first create the two new Pages “Titles.aspx” and “TitlesbyAuthor.aspx” . Now the “Titles.aspx” shows All the Tit