自定义ASP.NET MVC 404错误页面的路由 [英] Routing for custom ASP.NET MVC 404 Error page

查看:130
本文介绍了自定义ASP.NET MVC 404错误页面的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当有人键入URL时,我正在尝试创建自定义HTTP 404错误页面 不会在ASP.NET MVC中调用有效的动作或控制器,而是显示一般的找不到资源" ASP.NET错误.

I am trying to make a custom HTTP 404 error page when someone types in a URL that doesn't invoke a valid action or controller in ASP.NET MVC, instead of it displaying the generic "Resource Not Found" ASP.NET error.

我不想使用web.config来处理这个问题.

I don't want to use the web.config to handle this.

我有什么办法可以捕捉到无效的URL?

Is there any kind of routing magic I can do to catch any invalid URLs?

更新:我尝试了给出的答案,但是仍然收到难看的找不到资源"消息.

Update: I tried the answer given, however I still get the ugly "Resource Not Found" message.

另一个更新:好的,RC1显然有所更改.我什至尝试过专门在HttpException上捕获404,它仍然只为我提供找不到资源"页面.

Another update: Ok, apparently something changed in RC1. I've even tried specifically trapping 404 on an HttpException and it still just gives me the "Resource Not Found" page.

我什至没有使用过MvcContrib的资源功能,也没有使用-同样的问题.有什么想法吗?

I've even used MvcContrib's resource's feature and nothing - same problem. Any ideas?

推荐答案

只需在路由表的末尾添加捕获所有路由并显示您想要的任何页面即可.

Just add catch all route at the end of the routes table and display whatever page you want with it.

请参阅:

这篇关于自定义ASP.NET MVC 404错误页面的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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