前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ASP.NET MVC Routing Debugger路由调试工具

ASP.NET MVC Routing Debugger路由调试工具

作者头像
跟着阿笨一起玩NET
发布2018-09-20 15:13:20
7760
发布2018-09-20 15:13:20
举报

官网地址:http://blog.csdn.net/sgear/article/details/6789882

To  use this, simply download the following zip file and place the assembly inside of it into your bin folder. Then in your Global.asax.cs file add one line to theApplication_Start method (in bold).

代码语言:javascript
复制
protected void Application_Start(object sender, EventArgs e)
{
  RegisterRoutes(RouteTable.Routes);
  RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}

测试Routing

因为一个Url会匹配多个routing规则, 最后常常会遇到规则写错或者顺序不对的问题.于是我们希望能够看到Url匹配Routing的结果.

其中最简单的办法就是使用RouteDebug辅助类. 这个类需要单独下载dll组件, 我将此组件的下载放在了博客园上:

解压缩后是一个DLL文件, 将这个DLL文件添加到项目中并且添加引用.

使用方法很简单, 只需要在Application_Start方法中添加一句话:

代码语言:javascript
复制
RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);  

比如下面是我的示例中的代码:

代码语言:javascript
复制
 protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}  

现在你访问任何URL, 都会出现RouteDebug页面, 如下:

其中不仅有你的所有Routing规则, 还显示了是否匹配.并且按照顺序列出. 还有识别的参数列表.

当你不想测试Routing规则的时候则注释掉这一段, 即可回复跳转到View对象上.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015-06-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 测试Routing
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档