asp.net-mvcroutesregions

What is the preferred solution to dealing with dozens of route mappings in Global.asax


I was reading the following answer about regions on the topic of programming standards:

https://softwareengineering.stackexchange.com/questions/1338/worst-coding-standard-youve-ever-had-to-follow/1937#1937

I tend to agree with what @Cumbayah is saying, but I have to admit that there's one place where I'm relying on regions to keep the code tidy. That's in the Global.asax to keep my long list of routes somewhat legible.

The thing is, there's 5 - 10 Controllers and each has a handfull of routes into it, some specifically for certain action methods and others more general. So with that we're talking ~30,40,50ish route definitions defined in a single method in Global.asax. Right now I have them divided into different #Regions for each Controller to tidy it up a bit, but there sure is a stink off it! Is there a better way for me to do this?


Solution

    1. As per Noon, consider the use of Areas

    2. As per eglasius, consider moving the route registration concerns out of global.asax and into a separate file. Check out the RouteInitialiser class in the "Who Can Help Me" sample application for one way to do this.

    3. Consider DRY'ing up your route configuration by adopting a better route registration API, like Steve Hodgkiss's restful-routing stuff http://github.com/stevehodgkiss/restful-routing

    4. Don't sweat it. If you have lots of controllers, you will have lots of routes. Can't get around that ;)

    Oh, and 5) Get rid of your regions.