有没有办法可以在 ASP.NET 中调试路由.MVC5? [英] Is there a way I can debug a route in ASP. MVC5?
问题描述
过去我使用了一些我认为是微软的 Scott Hanselman 的代码.但是现在我使用的是 MVC5,我认为该代码不再有效.
In the past I have used some code by I think Scott Hanselman of Microsoft. However now I am using MVC5 and I don't think that code is valid any more.
有没有一种方法可以跟踪在 MVC5 中采用的路由,以便我知道为什么我会看到如下消息:
Is there a way I can trace routes taken in MVC5 so that I can know why I see messages like:
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
推荐答案
我知道现在对于 OP 来说已经晚了,但是对于其他任何试图调试 404 错误的人,我已经找到了一种拦截路由结果的方法,看看为什么会这样找不到资源.
I know it is late for the OP but for anyone else trying to debug 404 errors I've found a way to intercept the route result and see why it is failing to find the resource.
在 Global.asax.cs
中像这样覆盖 Init:
In Global.asax.cs
override Init like this:
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));
}
routeData
变量将保存正在解释的路由信息.我已经在 MVC5 上测试过了.
The routeData
variable will hold the route info as it is being interpreted. I've tested this on MVC5.
我最初在 Paul Evans 的另一个答案中遇到了这种方法,这是链接(感谢@porcus 找到它):stackoverflow.com/a/25466524
I originally bumped into this method in another answer by Paul Evans, this is the link (thanks to @porcus for finding it): stackoverflow.com/a/25466524
这篇关于有没有办法可以在 ASP.NET 中调试路由.MVC5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!