[ACCEPTED]-ASP.NET MVC Default route?-asp.net-mvc-routing

Accepted answer
Score: 35

Make sure the Default route is at the BOTTOM of your 4 listed route table. Order matters when 3 it comes to ASP.NET MVC Routing tables.

The 2 correct ordering is your 'most specific' route 1 to your least specific route.

Score: 18

Actually, George is right. MVC Routing respect ordering 5 route. Your last route must be generic as 4 possible, and your previous route must be 3 specific as possible.

In your case, both 2 are generic. You should

MapRoute("SomeAction", "Post/{action}", new {controller = "Post", role = "User");

and then

MapRoute("Default", new {controller="Home", action="Index", role = "Anonymous"});

so, you 1 give specificity to both routes.

Score: 13

Phil Haack released a route debugging tool that 4 can be invaluable in gaining an understanding 3 of problems like this.

With this tool you 2 can view how your MVC application parses 1 a URL and matches it to your RouteTable.

Score: 2

When you don't provide the route name or 6 the action is determined through a HTTP 5 request it will look in order from the order 4 they were added. The first time it finds 3 one that matches, it stops. So what's probably 2 happening is it's matching one previous 1 to the one you've added.

More Related questions