Routing with ASP.NET 4.0 has never been easier. While it was first a luxury
of ASP.NET MVC, WebForms applications got routing support with .NET 3.5 SP1. With
version 4.0 of the framework, setting up URL routing is now a piece of cake. For
those of you who have never heard of it: URL Routing enables your application to
use URLs that do not directly map to physical files, but can instead represent a
user-friendlier, more descriptive, logical structure. It is not
URL rewriting and not
URL mapping, where these effectively restore the original physical URL
of the page down the request pipe.
With version 2010.Q2 of Telerik RadControls for ASP.NET AJAX, RadGrid's SEO pager
now supports URL Routing. What does this mean? Well, prior to 2010.Q2, RadGrid used
Request.QueryString collection to extract the page index from the
page URL. This resulted in not very intuitive URLs with query strings to specify
the grid index:
The above URL is not the best in terms of brevity and readability. With URL
routing support, you can now use shorter and friendlier URLs without the clutter
of a lengthy query string:
The difference is obvious and URL routing is surely a good thing. Setting it up
is all a matter of giving values to a couple of properties in the grid:
Effectively, RadGrid requires that you indicate routing is used for your application
UseRouting). It then needs to know:
- The name of the route that leads to the target .aspx page containing the grid. Specified
in RadGrid by the
- The name of the URL parameter that specifies the current page index. Specified in
RadGrid by the
In the above diagram, I have defined a route in Global.asax file that leads to Default.aspx.
The route defines a single URL parameter with a default value of 1. This parameter
will be used to specify the current page index in RadGrid. To take advantage of
this route setup, I have configured RadGrid's pager to use this route. I have set
the route name and the name of the URL parameter that specifies the page index.
With URL Routing, RadGrid no longer needs query strings to use SEO paging:
Anyone else think it's elegant?