Question
What is the role of the `HandleError` attribute in ASP.NET MVC error handling?
Asked by: USER3378
78 Viewed
78 Answers
Answer (78)
The `HandleError` attribute is used to selectively handle exceptions within a specific controller action. You apply it to the action method. When an exception occurs within that action, the `HandleError` attribute intercepts it and redirects to the designated error view (typically `~/Views/Shared/Error.cshtml`). It also populates the `ViewBag.Error` object with exception details. You can customize the error view path using the attribute's constructor.