Typed Routing

No more magic strings - especially when it comes to request routing!
Snooze uses typed expressions to define routes. 

The Basics

Create a Url class that explicitly defines the parameters, then describe how they fit into the route url with an expression.

public class ArticlesUrl
{
    public int Year { get; set; }
    public int Month { get; set; }
    public int Day { get; set; }
}

// In the Global.asax RegisterRoutes method:
    routes.Map<ArticlesUrl>(a => "articles/" + a.Year + "/" + a.Month + "/" + a.Day);

The created route url will look like "articles/{Year}/{Month}/{Day}".

The usual ASP.NET routing rules apply. You can use "-" and "." as separators as well as "/".

Your expression must be a string. If it has a single non-string value, then just put a .ToString() on the end of it. Luckily the C# compiler knows that "string + int" => "string", so for most cases it's fine.

Defaults Parameter Values

For example, let's say we want the Day parameter default to 1, if not present in the url. Use the Default extension method when defining the route:

routes.Map<ArticlesUrl>(a => "articles/" + a.Year + "/" + a.Month + "/" + a.Day.Default(1));

Catch-all Parameter

Do you need your last route parameter to catch the all of the remaining path? Use the CatchAll extension method:

routes.Map<ContentUrl>(c => "contents/" + c.ContentPath.CatchAll());

This will create the route url "contents/{*ContentPath}", so it can handle requests like "contents/foo/bar/qux.xml".