URL Routing with Kentico CMS
Does Kentico CMS support URL routing? Read this article to learn more ...
Hi there,
ASP.NET 3.5 came with an interesting feature called URL Routing, we will look at what it does more closely and compare it to our Wildcard URLs.
What is the ASP.NET URL routing?
The ASP.NET routing mechanism is basically URL rewriting evolved to support handling of dynamic context specific URL by a single page. Originally, it was made only for pure MVC development model, but it extended to WebForms with .NET 4.0.
Here is some basic introduction to it:
http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx
With WebForms URL routing, you typically define something like a lookup table in your Application_Start method, which says what URLs should be translated to which physical pages.
To register the route, you just register the page with the given "wildcard" with named parameters:
routes.MapPageRoute("products-browse", "products/{category}", "~/Products.aspx");
-
products-browse is a name of the route
-
products/{category} is the URL wildcard
-
~/Products.aspx is the processing page
So basically if you access
products/CPUs, you get to the page
~/Products.aspx and you can pull the parameter
category from you context, using several ways how to access it either declaratively or functionally.
It is kinda nice if you ask me, but the need to register all my possible URL formats from App_Start? No thanks! We provide better options ...
What are Kentico CMS URL wildcards?
This may seem like a deja vu, but Kentico CMS URL wildcards is basically URL rewriting extension to support handling of dynamic context specific URL by a single page. Sounds familiar? It should ... :-)
Yes, if you look more closely at the Kentico CMS URL wildcards, you can very easily see that it is quite the same thing, yet a little different in how you use it.
With Kentico CMS, you have your
/Products page in your content tree, that is your displaying context.
If you go to the document properties and set the URL path to
/products/{category} (again, seems familiar?), you just defined your dynamic context URL for that page.
The route name is not needed in this case, since the context is basically the document itself.
Similar to ASP.NET routing, when the request comes to the server, it is processed by the document template (either ASPX or Portal) and your controls typically use the querystring parameter or macro to get the route parameters.
So we have basically the same settings (even with same syntax) in background, here are the differences:
-
Kentico CMS is not based on ASP.NET routing engine
-
You can find the wildcard parameter directly in your querystring and use it in macros (there is no specialized collection for it)
-
Kentico CMS routing works dynamically as you set it in the document's properties, no need to define some static routing table in App_Start.
So the conclusion is that you
may use the routes very well if you use them through our wildcard URLs.
See the complete documentation on Wildcards here:
http://devnet.kentico.com/docs/devguide/wildcard_urls.htm
Or watch the webinar on URL rewriting here:
http://devnet.kentico.com/Blogs/Martin-Hejtmanek/December-2009/Webinar-3---URL-rewriting-and-processing-in-Kentic.aspx
Why is our implentation different?
There are several reasons why Kentico CMS isn't based on the ASP.NET routing, they are following:
-
First of all, we need it to be dynamic and directed by the document data from the database.
-
We still support ASP.NET 2.0, and routing for WebForms is available from .NET 4.0.
-
We may need to improve it even more in the future, which could be hard being bound with some other solution limitations. (we still may think about it in future, we will see)
-
The fact that the syntax we use is the same is just a fortunate coincidence :-)
What's next?
That's it, now you know you don't need to take care about ASP.NET routing, you may use our wildcard URLs instead of it with more flexibility.
See you next time ...