URL 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
the 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:
http://myapplication.com/mygrid.aspx?RadGrid1ChangePage=2&RadGrid2ChangePage=5
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:
http://myapplication.com/mygrid/2
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
(by setting UseRouting
). It then needs to know:
SEORouteName
property.SEOPageIndexRouteParameterName
.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?
UPDATE: RadControls for ASP.NET AJAX beta is out, so if you want to try the Routing support for RadGrid's SEO pager yourself, attached is a .NET 4.0 sample project you just have to run. Happy routing!
Iana Tsolova is Product Manager at Telerik’s DevTools division. She joined the company back in the beginning of 2008 as a Support Officer and has since occupied various positions at Telerik, including Senior Support Officer, Team Lead at one of the ASP.NET AJAX teams and Technical Support Director. Iana’s main interests are web development, reading articles related to geography, wild nature and latest renewable energy technologies.