有没有一种方法可以在ASP中调试路由. MVC5? [英] Is there a way I can debug a route in ASP. MVC5?

查看:76
本文介绍了有没有一种方法可以在ASP中调试路由. MVC5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去,我使用过Microsoft的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中调试路由. MVC5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆