views:

1441

answers:

5

I've tried this both with and without the 'ExceptionType' parameter. I have an Error.aspx page in both the Views/Shared folder and the Views/thisController folder. But everytime I run this I get a "Server Error in '/' Application." error page, rather than the nice one in Views/Shared.

Any idea what could be going wrong here?

[HandleError(View="Error",ExceptionType=typeof(FormatException))]

    public ActionResult Create()
    {
        throw new Exception();
        //int breakMe = int.Parse("not a number");
        return View();
    }
A: 

I'm getting the same issue as we speak. I can get it working on a new MVC Application but not my existing one.

Weird

Schotime
+1  A: 

It doesn't work for me on my current project or a new one. It's probably a "feature".

EDIT: it looks like you have customErrors enabled (mode="On") for it to work according to this snippet from HandleErrorAttribute.cs:

// If custom errors are disabled, we need to let the normal ASP.NET exception handler
// execute so that the user can see useful debugging information.
if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled) {
  return;
}
Todd Smith
+2  A: 

I do indeed have this in my web.config

<customErrors mode="On"></customErrors>

Must be something else at play.

Schotime
When I change mode from RemoteOnly to On it started working for me.
Todd Smith
I figured it out. Its because i'm using a custom view engine so that all my pages are in an app directory like Rob Conery does for the MVC storefront. The HandleError does not work in this situation..Could be an MVC bug.
Schotime
I have emailed Phil Haack and this is confirmed as a bug.
Schotime
A: 

Good call guys, once I changed the customErrors mode property from 'remoteOnly' to 'On' it did indeed start working! Thanks!

Jeff Keslinke
A: 

I'm having problems with this too, and I can't get it to work on my local workstation when just opening a new ASP.NET MVC Application template project, adding the HandleError attribute to the Index controller and the following line to the Index method:

throw new ApplicationException("oops...");

I get the standard ASP.Net Error Page.

Tomas Lycken