您的位置:首页 > 编程语言 > ASP

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

2015-06-28 16:59 791 查看
官网地址: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 the
Application_Start
method (in bold).

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方法中添加一句话:

RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes); 


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


 protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
} 


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




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

当你不想测试Routing规则的时候则注释掉这一段, 即可回复跳转到View对象上.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: