Let’s say I have a few controllers with long names like VeryLongNameController.
By default ASP.NET MVC3 will map ~/VeryLongName or ~/verylongname to this controller. However I don’t like the use of capital names within the URL and would like it to map all long named controllers like ~/very-long-name instead.
I know that it’s possible to add custom routes one by one, but is there a way to change the default behavior?
I’ve investigated this a bit more, and got it working by making my own IHttpHandler and IRouteHandler, looking at the source for System.Web.Mvc.MvcHandler and System.Web.Mvc.MvcRouteHandler and basically copying and pasting and replacing how it resolves the controller name. However I don’t like this approach at all, as it feels too heavy-weight to redo the whole request processing pipe for a simple cosmetic task. Thus, I will go with adding manual routes for each controller which has two names (which there aren’t that many).
UPDATE: I’ve come with a much simpler solution, and that is done through overriding ControllerFactory .
My blog post about it: http://cangencer.wordpress.com/2011/05/27/better-looking-urls-in-asp-net-mvc-3/