How do you debug MVC 4 API routes?

解答1

RouteDebugger is good for figuring out which routes will/will not be hit.

http://nuget.org/packages/routedebugger

解答2

Another way is to add an event handler in Global.asax.cs to pick up the incoming request and then look at the route values in the VS debugger. Override the Init method as follows:

public override void Init()
{
base.Init();
this.AcquireRequestState += showRouteValues;
} protected void showRouteValues(object sender, EventArgs e)
{
var context = HttpContext.Current;
if (context == null)
return;
var routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(context));
}

Then set a breakpoint in showRouteValues and look at the contents of routeData.

Keep in mind that in a Web API project, the Http routes are in WebApiConfig.cs, not RouteConfig.cs.

ASP.NET Routing Debugger

PDATE: I’ve added a NuGet package named “routedebugger” to the NuGet feed, which will make it much easier to install.

UPDATE 2: In newer versions of the NuGet package you don’t need to add code to global.asax as described below. An appSetting <add key="RouteDebugger:Enabled" value="true" /> in web.config suffices.

https://www.nuget.org/packages/routedebugger/

最新文章

  1. WebService中使用Aspose.Cells.dll
  2. windows下在文件夹中快速启动cmd
  3. 《你必须知道的.NET》读书笔记二:小OO有大原则
  4. 在使用androidStudio中所遇到的错误
  5. RabbitMQ官方中文入门教程(PHP版) 第一部分:Hello World
  6. Android studio 查看签名
  7. javascript中prototype、constructor以及__proto__之间的三角关系
  8. Transform-style和Perspective属性
  9. Java程序员从笨鸟到菜鸟之(二十一)java过滤器和监听器详解 【转】
  10. 从零开始学习jQuery (十一) 实战表单验证与自动完成提示插件
  11. DotNetCore跨平台~Dockerfile的解释
  12. 梳理:python—同一个类中的方法调用
  13. vue上传图片
  14. [转帖]Windows 10新预览版上线:可直接运行任意安卓APP了
  15. spring cloud ----&gt; RibbonClient设置的熔断器Hystrix不起作用
  16. 安装docker CE for CentOS
  17. Maven 问题笔记汇总
  18. 数据库mysql的常规操作
  19. 【IIS】IIS 7.0/7.5 无法启动 w3svc 服务
  20. Windows x64 栈帧结构

热门文章

  1. OpenStack kilo版(5) Neutron部署
  2. 还想免费继续使用JDK吗?从java11以后别从Oracle下载了
  3. Go数据类型之基本数据类型
  4. Linux提供哪些功能
  5. Java中实现图片的上传
  6. 重新编程Hexiwear Docking Station扩展坞
  7. Luogu P2935 最好的地方Best Spot
  8. Educational Codeforces Round 41 (Rated for Div. 2) D. Pair Of Lines (几何,随机)
  9. Python获取爬虫数据, r.text 与 r.content 的区别
  10. grep redis-cli command