schourode/canonicalize — Issue #2: MVC 4.0 and Route Registration
Author: jedhunskaer
Created: 2011-12-11 10:23:47+00:00
State: open

Perhaps I'm doing it wrong, but have you gotten this to work with MVC 4.0? I have the following in my route registration, as the documentation says, before any existing registrations; yet, it doesn't appear to be working (i.e. my URLs are still camel case and such). I'm just using the default registrations in a fresh MVC 4.0 install, like so...

public static void RegisterRoutes(RouteCollection routes)
{
routes.Canonicalize().NoWww().Pattern("([a-z0-9])([A-Z])", "$1-$2").Lowercase().NoTrailingSlash();

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}

Should I not be using the MapRoute method like that?

Notice, I've added a pattern in the hopes that I can replace camel case urls with hyphens instead; though, I'm looking for a better solution, as I know this wouldn't work anyway. I'm just looking for a way to enforce hypens w/o changing the names of the ActionResults.