Tag: 自定义错误页面的

ASP.NET MVC的HandleError

我如何去在asp.net MVC预览5中的[HandleError]filter? 我在我的Web.config文件中设置了customErrors <customErrors mode="On" defaultRedirect="Error.aspx"> <error statusCode="403" redirect="NoAccess.htm"/> <error statusCode="404" redirect="FileNotFound.htm"/> </customErrors> 并把[HandleError]放在我的控制器类上面,如下所示: [HandleError] public class DSWebsiteController: Controller { [snip] public ActionResult CrashTest() { throw new Exception("Oh Noes!"); } } 然后我让我的控制器从这个类inheritance,并调用CrashTest()。 Visual Studio暂停在错误,并按f5继续后,我重新路由到Error.aspx?aspxerrorpath = / sxi.mvc / CrashTest(其中sxi是所用的控制器的名称。当然path无法find,我得到“/'应用程序中的服务器错误”404。 这个网站已经从预览版3移植到了5.除了error handling以外,所有的东西都运行(并没有太多的工作来移植)。 当我创build一个完整的新项目,error handling似乎工作。 想法? – 注意 – 由于这个问题现在有超过3K的意见,我认为这是有利的,把我目前(ASP.NET MVC 1.0)使用。 在mvc contrib项目中有一个叫做“RescueAttribute”的精彩属性,你也许应该检查一下;)