Cymen Vig

Software Craftsman

ASP.NET MVC Route Registration and Areas

I need to be able to register a route via an instance of RouteCollection to an area. I couldn’t put it in the normal area route registration as it had to be registered last. It took a while to figure out that this works:

public static void RegisterAreaRoute(RouteCollection routes) {
    routes.MapRoute(
        "MyRouteName",
        "{*path}",
        new
        {
            // options
        },
        new[] { "_Namespace_.Areas._Area_Name_.Controllers" }
    ).DataTokens.Add("area", _Area_Name_);
}