Knowledge is power. We love to share it.

News related to Mono products, services and latest developments in our community.


ASP.NET routing support in MonoX

04/06/2010Categories: MonoX
Service Pack 1 for the Microsoft .NET Framework 3.5 introduced a number of important changes, including the ASP.NET routing engine. Although routing is traditionally associated with ASP.NET Model View Controller (MVC) framework, Microsoft decide to package the routing logic into the System.Web.Routing assembly and to release this assembly with SP1. This was a nice move, since it enabled us to easily integrate the routing technology into MonoX.
However, you may wonder what's the difference between the ordinary URL rewriting and this new technology. Both allow us to build friendly, "hackable" URLs for our Web applications - however, the routing engine can decouple the URL in an incoming HTTP request from the physical Web Form that responds to the request. This is natural to developers that are using MVC - 1:1 relationship between an incoming URL and the physical aspx page is now gone. Additionally, URL rewriting is a one-way translation mechanism because there is no easy mechanism to let the URL rewriting logic work in both directions.  In another words, it was difficult to give the rewriting logic the internal URL of a Web form and have it return a public URL required to reach this form. Routing engine allows you to translate URLs both ways.

There are many more important design decisions behind this new feature. Scott Allen has a nice article on MSDN magazine that describes all you need to know about routing with Web forms. Phil Haack and Chris Cavanagh recently published a series of in-depth blog posts related to this topic - a mix of their techniques were used to introduce the full routing support in MonoX. Daniel Fisher helped us with his implementation of query parameters support, something that was neccessary since MonoX relies on query parameters for localization and similar purposes.

Attached is a simple package that can be used to add the support for routing in your MonoX-based projects. Include the classes from the routing folder in the App_Code of your application (change the namespace as you wish), and use the skeleton code from the BasePage in your project's base page. Additionally, make sure that the routing-dependant entries from the attached web.config file are present in your web.config.

For a taste of things to come, read more about WebForm routing in ASP.NET 4.0.

On a side note, SP1 also introduced Dynamic Data, a very neat scaffolding mechanism that enables developers to create data-driven applications with minimal or no code. We will cover this technology and its integration with MonoX in a few weeks.


This content has not been rated yet.