ASP.NET MVC Routing - but better

2008-03-28 @ 10:20#

i was pleased to see this post from Fredrik Kalseth that shows how to modify the ASP.NET MVC engine to support Regular Expressions for their Routing class. i understand the initial decision to *not* use RegEx for routes in the ASP.NET MVC framework. it's likely a majority of developers don't have the RegEx chops to start with. however, as soon as you start doing serious work with routing, you'll realize RegEx is essential.

i also note that Fredrik points to a doubt he has about the current routing implementation in ASP.NET MVC:

Even with regular expression support, I'm still not 100% happy with the routing; it won't allow me to overload controller actions. In the above example, for instance, I would much rather have two separate Find(string query) and Find(int ssn) methods, and then have the correct one invoked depending on whether the query or SSN parameter was present in the route - but the MvcRouteHandler doesn't know how to resolve that and just throws an exception.

i guess this is a good time to point out that the exyus web engine supports RegEx routing *and* allows you to apply multiple routes to the same resource class:

// echo back simple content
[UriPattern(@"/samples/virtual/.xcs", @"/virtual/hello(?:\.xcs)(?:.*)?")]
public class StartPage : StaticResource
{
    public StartPage()
    {
        this.Content = "<h1>hello $name$</h1>";
    }
}

code