在Asp.Net MVC(RC 5)404 HTTP错误处理程序 [英] 404 Http error handler in Asp.Net MVC (RC 5)
本文介绍了在Asp.Net MVC(RC 5)404 HTTP错误处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何处理程序404错误,而框架抛出异常的500错误code?
How can I Handler 404 errors without the framework throwing an Exception 500 error code?
推荐答案
<一个href=\"http://jason.whitehorn.ws/2008/06/17/Friendly-404-Errors-In-ASPNET-MVC.aspx\">http://jason.whitehorn.ws/2008/06/17/Friendly-404-Errors-In-ASPNET-MVC.aspx给出了如下解释:
添加一个通配符路由规则作为最终的规则:
Add a wildcard routing rule as your final rule:
routes.MapRoute("Error",
"{*url}",
new { controller = "Error", action = "Http404" });
这不符合其他规则的任何请求被路由到错误控制器的HTTP404行动,您还需要配置:
Any request that doesn't match another rule gets routed to the Http404 action of the Error controller, which you also need to configure:
public ActionResult Http404(string url) {
Response.StatusCode = 404;
ViewData["url"] = url;
return View();
}
这篇关于在Asp.Net MVC(RC 5)404 HTTP错误处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文