asp.net-mvcerror-handlingasp.net-mvc-5custom-errorshandleerror

How can I make the HandleError attribute work without web.config setting (customErrors)?


I can't get [HandleError] attribute in MVC 5 to work.

I have this Controller

[HandleError]
public class HomeController : Controller
{
    public ActionResult WelcomePage()
    {
        throw new Exception("Oops!");
        return View();
    }
}

Which gives the yellow screen of death.

If I add in the web.config

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

it works. But if I remove the [HandleError] it still works, so it's setting in the web.config has higher presedense I guess.

But should't you be able to only use the [HandleError] without relying on some web.config setting?


Solution

  • The HandleError filter handle exceptions only if the customErrors is turned on in web.config

    see this link for more details: http://www.prideparrot.com/blog/archive/2012/5/exception_handling_in_asp_net_mvc