asp.net MVC HandleError

Posted by boris callens on Stack Overflow See other posts from Stack Overflow or by boris callens
Published on 2008-10-08T15:12:32Z Indexed on 2010/05/04 22:18 UTC
Read the original article Hit count: 398

Filed under:
|

How do I go about the [HandleError] filter in asp.net MVC Preview 5?
I set the customErrors in my web.config file

<customErrors mode="On" defaultRedirect="Error.aspx">
  <error statusCode="403" redirect="NoAccess.htm"/>
  <error statusCode="404" redirect="FileNotFound.htm"/>
</customErrors>

and put [HandleError] above my Controller Class like this:

[HandleError]
public class DSWebsiteController: Controller{
    [snip]
    public ActionResult CrashTest() {
        throw new Exception("Oh Noes!");
    }
}

Then I let my controllers inherit from this class and call CrashTest() on them. Visual studio halts at the error and after pressing f5 to continue, I get rerouted to Error.aspx?aspxerrorpath=/sxi.mvc/CrashTest (where sxi is the name of the used controller. Off course the path cannot be found and I get "Server Error in '/' Application." 404.

This site was ported from preview 3 to 5. Everything runs (wasn't that much work to port) except the error handling. When I create a complete new project the error handling seems to work.

Ideas?

--Note--
Since this question has over 3K views now, I thought it would be beneficial to put in what I'm currently (asp.net mvc 1.0) using. In the mvc contrib project there is a brilliant attribute called "RescueAttribute" You should probably check it out too ;)

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about handleerror