In this blog post I would like to talk about a new ASP.Net 4.0 feature, URL Routing. I know this issue has been explained from various people on the web but I will give my own example.
We could implement routing since ASP.Net 3.5 SP1 but it was there primarily to support ASP.Net MVC. Even in that release you could implement rounting in web forms but it was a quite difficult thing to do.
However in ASP.Net 4.0 there is an integrated support for routing. It becomes easy to map requests in your site onto pages in your application.
This is made possible with the introduction of the handler PageRouteHandler that is responsible for dispatching routes onto pages. There is also the MapPageRoute function of the RouteCollection collection that defines a route handled by a page.
Our main goal when designing and implementing web sites is to make them highly discoverable by the search engines. In other words to make them SEO friendly. ASP.Net focuses on SEO and provides us with many SEO oriented features.
Have a look in this post of mine for more SEO features in ASP.Net 4.0.It makes no sense to have an e-commerce website or a website that you place you cv and noone is able to discover this page.
I will demonstrate routing by providing a step by step example using VS 2010 Ultimate edition, C# 4.0 and ASP.Net 4.0.
void Application_Start(object sender, EventArgs e)
// Code that runs on application startup
MapPageRoute("TheProduct", "product", "~/products.aspx");
7) Run your application again and type
Congratulations, you have successfully used routing in ASP.Net 4.0.Please note that the original URLs are still valid,
Hope it helps!!!