简体   繁体   中英

How to determine if mapped route is being used in ASP.NET MVC solution

I'm working on the route configuration of a solution that previously had many unnecessary calls to RouteCollection.MapRoute() which essentially could all be replaced with a default route by merely changing the ActionResult methods a little. Now I'm down to just one route besides the default and I'm having a hard time telling if it's being used anywhere in the solution. The code now looks like this:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{directory}/{resource}.asmx/{*pathInfo}");

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",  
    new { controller = "Home", action = "Index", id = "" }
);

routes.MapRoute("GridPaging", "{controller}/{action}/{page}", null);

The variable routes is an instance of RouteCollection . So, is there some way I can determine if the GridPaging route is actually being used anywhere? As an aside, Visual Studio indicates that the overload being used for that call to MapRoute is the one where the fourth parameter is the string array of namespaces . I'm not sure how it decides on that signature given the null argument could supposably resolve to this overload as well.

Take a look at Phill's post here and find witch route your app is using.

The way your routes are configured, you only get the GridPaging route if you use RouteName, with default route resolution you'll get on Default route because they essentially has the same path.

"GridPaging" is a route name, so searching for "GridPaging" in your code should tell you where this route is used.

If you would like to see more which route is called you can install and use Route Debugger from NuGet.

Here is a link on how to use Route Debugger

EDIT:

If you are using ASP.NET MVC you can get ASP.NET MVC Routing Debugger Visualizer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM