在的Application_Error MVC 3不解雇404时,URL中包含4个或更多路径段 [英] Application_Error not fired for 404 in MVC 3 when url contains 4 or more path segments

查看:101
本文介绍了在的Application_Error MVC 3不解雇404时,URL中包含4个或更多路径段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想404错误创建自定义错误页。我已经实现在Global.asax.cs中Application_Error事件。在大多数情况下此工程巨大,但该方法是没有得到要求有4个或多个路径段的URL。

I am trying to create a custom error page for 404 errors. I have implemented the Application_Error method in Global.asax.cs. For the most part this works great, but the method isn't getting called for URLs with 4 or more path segments.

这是我遇到的麻烦,具体网址为:

The specific URL that I'm having trouble with is:

http://localhost/Area/Controller/Action/ID

如果我删除了ID,我的自定义404岁加载罚款。这个问题似乎是一种在我的路径(/区/控制器/动作/ ID)4个级别。任何想法?

If I remove the ID, my custom 404 age loads fine. The problem seems to be having 4 levels in my path (/Area/Controller/Action/ID). Any ideas?

推荐答案

我怀疑你的路由时,不考虑与4个部分的URL。尝试添加一个包罗万象的所有路线的为您上次的路线,以测试这个:

I suspect your routes don't account for a URL with 4 parts. Try adding a catch all route as your last route to test this:

routes.MapRoute("Error404", "{*url}", new {controller = "Error", action = "PageNotFound" );

包括:(一些)你在你的问题也可能有助于路线。

Including (some of) your routes in your question might also help.

这篇关于在的Application_Error MVC 3不解雇404时,URL中包含4个或更多路径段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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