简体   繁体   English

如何确定在ASP.NET MVC解决方案中是否使用了映射的路由

[英]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. 我正在研究一种解决方案的路由配置,该解决方案以前对RouteCollection.MapRoute()进行了许多不必要的调用,实际上,只需稍微更改ActionResult方法,就可以全部替换为默认路由。 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 . 变量routesRouteCollection一个实例。 So, is there some way I can determine if the GridPaging route is actually being used anywhere? 因此,有什么方法可以确定GridPaging路由是否真正在任何地方使用? 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 . 顺便说一句,Visual Studio指示用于MapRoute调用的重载是其中的重载, 其中第四个参数是namespaces的字符串数组 I'm not sure how it decides on that signature given the null argument could supposably resolve to this overload as well. 我不知道它是如何决定给出的空论点签名会supposably解析到这个重载为好。

Take a look at Phill's post here and find witch route your app is using. 此处查看Phill的帖子,查找您的应用程序正在使用的巫婆路线。

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. 路由的配置方式,只有在使用RouteName的情况下,才获得GridPaging路由,而默认路由解析将在默认路由上得到,因为它们实质上具有相同的路径。

"GridPaging" is a route name, so searching for "GridPaging" in your code should tell you where this route is used. “ GridPaging”是路由名称,因此在代码中搜索“ GridPaging”应该告诉您使用该路由的位置。

If you would like to see more which route is called you can install and use Route Debugger from NuGet. 如果您想查看更多被调用的路由,可以从NuGet安装和使用Route Debugger

Here is a link on how to use Route Debugger 这是有关如何使用Route Debugger的链接

EDIT: 编辑:

If you are using ASP.NET MVC you can get ASP.NET MVC Routing Debugger Visualizer 如果使用的是ASP.NET MVC,则可以获得ASP.NET MVC路由调试器可视化器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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