The simplest thing to do is to add the locationId
route value to each location
route.
routes.MapRoute(
name: "location1",
url: "location1/{controller}/{action}/{id}",
defaults: new { locationId = "1", id = UrlParameter.Optional });
routes.MapRoute(
name: "location2",
url: "location2/{controller}/{action}/{id}",
defaults: new { locationId = "2", id = UrlParameter.Optional });
Assuming your locations will include the number, you could use a regex route constraint to make it a bit more dynamic:
routes.MapRoute(
name: "location",
url: "location{locationId}/{controller}/{action}/{id}",
defaults: new { id = UrlParameter.Optional },
constraints: new { locationId = @"\d+" });
Or you could implement IRouteConstraint
to make your locations completely text-based without including the ID, which allows you to map it based on dynamic data.
Another option for database driven data that lets you deal with more than one segment at a time is to create a RouteBase
subclass and put your logic there.
Or, you could create .NET Reflection/logic driven routes that are automatically generated and added to the route table, like in this example (but do note that this should only be done at application startup).