我怎样才能让一个包罗万象的途径来处理“404找不到网页”ASP.NET MVC的疑问? [英] How can i make a catch all route to handle '404 page not found' queries for ASP.NET MVC?

查看:147
本文介绍了我怎样才能让一个包罗万象的途径来处理“404找不到网页”ASP.NET MVC的疑问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能创建一个捕获所有的最终路线..和反弹用户在ASP.NET MVC?

Is it possible to create a final route that catches all .. and bounces the user to a 404 view in ASP.NET MVC?

请注意:我不希望在我的IIS设置来设置此

NOTE: I don't want to set this up in my IIS settings.

推荐答案

找到自己的答案。

<一个href=\"http://richarddingwall.name/2008/08/17/strategies-for-resource-based-404-errors-in-aspnet-mvc/\">Richard丁沃尔具有优良的岗位通过各种策略去。我特别喜欢FilterAttribute解决方案。我不是抛出异常各地威利愿意不愿意的粉丝,所以我会看看我是否能在改善:)

Richard Dingwall has an excellent post going through various strategies. I particularly like the FilterAttribute solution. I'm not a fan of throwing exceptions around willy nilly, so i'll see if i can improve on that :)

有关在Global.asax,只需添加这code作为你最后的路线进行注册:

For the global.asax, just add this code as your last route to register:

routes.MapRoute(
    "404-PageNotFound",
    "{*url}",
    new { controller = "StaticContent", action = "PageNotFound" }
    );

这篇关于我怎样才能让一个包罗万象的途径来处理“404找不到网页”ASP.NET MVC的疑问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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