asp.net-mvcexceptionhandleerror

ASP.net MVC [HandleError] not catching exceptions


In two different application, one a custom the other the sample MVC application you get with a new VS2008 MVC project, [HandleError] is not catching exceptions.

In the sample application I have:

[HandleError]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewData["Message"] = "Welcome to ASP.NET MVC!";
        throw new Exception();
        return View();
    }

    public ActionResult About()
    {
        return View();
    }
}

which is just the default controller with an exception being thrown for testing.

But it doesn't work. Instead of going to the default error.aspx page it shows the debug information in the browser.

The problem first cropped up in a custom application I'm working on which led me to test it with the sample application. Thinking it had something to do with changes I made in the custom application, I left the sample application completely unchanged with the exception (yuck) of the throw in the index method.

I'm stumped. What am I missing?


Solution

  • In Web.config, change customErrors:

    <system.web>
      <customErrors mode="On">
      </customErrors>
    

    If mode is either Off or RemoteOnly, then you will see the yellow screen of death instead of the custom error page. The reasoning is that developers usually want the more detailed information on the yellow screen of death.