How do I distinguish between these 2 MVC routes?
I have these routes in my area registration. It seems the second route is giving me resource Not found error.
context.MapRoute(
"viewer",
"forum/{id}",
new { controller = "View", action = "Index" }
);
context.MapRoute(
"contacts",
"forum/contacts",
new { controller = "Contacts", action = "Index" }
);
context.MapRoute(
"app_home",
"forum/",
new { controller = "Home", action = "Index" }
);
It seems the first route is blocking the urls for the second one. The action's controllers are different: Test and Contacts.
Sample url for first route:
www.<mysite>/forum/12345 <-- view fo开发者_StackOverflowrum 12345
Sample url for second route:
www.<mysite>/forum/contacts <-- view contacts homepage
Sample url for third route:
www.<mysite>/forum <-- forum homepage
How can I make these urls distinct in the routes?
Put the contacts
route first.
Routes are ordered; the routing engine will always select the first matching route.
Therefore, you should always put the most specific routes first.
精彩评论