zoukankan      html  css  js  c++  java
  • ASP.NET MVC Routing Debugger路由调试工具

    官网地址: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).

    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对象上.

  • 相关阅读:
    目录路径加反斜杠和不加的区别
    window端口号被占用解决
    个人博客设计记录
    2017/12/15
    添加code到github上
    跨域简介
    客户端存储
    window.name跨域
    BZOJ1305: [CQOI2009]dance跳舞
    BZOJ4872: [Shoi2017]分手是祝愿
  • 原文地址:https://www.cnblogs.com/51net/p/4605773.html
Copyright © 2011-2022 走看看