Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you debug "No route in the route table matches the supplied values." in ASP.NET MVC

Tags:

asp.net-mvc

I seem to run into this error all the time:

No route in the route table matches the supplied values.

An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

The stack trace is just a bunch of MVC garbage.

Obviously I am querying for a non-existent route, but how do I discover which route it was actually trying to query? I would love to know the actual URL and HTTP Method. How can I discover this?

(I'm used to Django where the attempted URL is a part of the exception and would prefer a more efficient method than viewing the source of my page and figuring it out.)

like image 592
Frank Krueger Avatar asked May 25 '09 18:05

Frank Krueger


People also ask

What is routes MapRoute in MVC?

routes. MapRoute has attributes like name, url and defaults like controller name, action and id (optional). Now let us create one MVC Application and open RouteConfig. cs file and add the following custom route.

What is route constraint in MVC?

The Route Constraint in ASP.NET MVC Routing allows us to apply a regular expression to a URL segment to restrict whether the route will match the request. In simple words, we can say that the Route constraint is a way to put some validation around the defined route.

Where is route table in ASP.NET MVC?

The route table is created during the Application Start event. The file in Listing 1 contains the default Global. asax file for an ASP.NET MVC application. When an MVC application first starts, the Application_Start() method is called.

How many routes can be defined in the MVC application?

there are no limits in creating routes. You can create as many route as you want in your RouteConfig. cs file. But make sure that you provide unique name value to each MapRoute function.


2 Answers

There's a nice route debugger.

like image 82
Darin Dimitrov Avatar answered Oct 28 '22 04:10

Darin Dimitrov


You can use the MvcContrib's RouteDebugger utility class to get a better view what route was handled the request.

All you need to do is add a reference to the MvcContrib, and add this code to the Global.asax

RegisterRoutes(RouteTable.Routes);
RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
like image 29
Fitzchak Yitzchaki Avatar answered Oct 28 '22 02:10

Fitzchak Yitzchaki