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

查看:49
本文介绍了自定义 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?

推荐答案

只需在路由表的末尾添加 catch all route 并使用它显示您想要的任何页面.

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

参见:如何制作一条捕获所有路由来处理 ASP.NET MVC 的404 页面未找到"查询?

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

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