I have routes set up like:
context.MapRoute(
name: "Area",
url: "Area/{controller}/{action}",
defaults: new
{
controller = "Home",
action = "Dashboard"
}
);
context.MapRoute(
name: "AccountArea",
url: "Area/{accountFriendlyId}/{controller}/{action}",
defaults: new
{
controller = "Home",
action = "Dashboard",
accountFriendlyId = RouteParameter.Optional
}
);
context.MapRoute(
name: "AccountCampaignArea",
url: "Area/{accountFriendlyId}/{campaignFriendlyId}/{controller}/{action}",
defaults: new
{
controller = "Home",
action = "Dashboard",
accountFriendlyId = RouteParameter.Optional,
campaignFriendlyId = RouteParameter.Optional
}
);
And I have a burning desire to have Area/friendlyAccountName/Home
take me to the Dashboard()
but this doesn't work (404). I think the reason is that we go looking for a friendlyAccountName controller.
Comfortable with the knowledge that if I should choose to name an account after one of my controllers everything comes crashing down, is there a way to fall through to the next route in case of a string failing to find a corresponding controller? Is there some way to use reflection and avoid maintaining a constraint every time I modify the list of my controllers?
EDIT
Do you know a way that doesn't use reflection or at least contains the derived type search to this area? I don't like the idea of incurring that overhead twice when the second route parameter does match a controller name (pass constraint then search again when constructing controller). I wish there was a way to catch the exception at the point of constructing a controller and then backing up and falling through to the next route.