Custom HandleErrorAttribute

I want to display all errors on one page (without redirecting / changing the contents of the page) where this happened (for example, a javascript warning), and I think that the error page may load as a PartialView. I am trying to create a custom HandleErrorAttribute, but it does not work:

public class CustomHandleErrorAttribute : HandleErrorAttribute
{
    public string PartialViewName { get; set; }

    public override void OnException(ExceptionContext filterContext)
    {
        var result = new PartialViewResult();
        result.ViewName = PartialViewName;
        filterContext.Result = result;
    }
}
+3
source share
1 answer

Try something like this:

protected override void OnException(ExceptionContext filterContext)
{
    filterContext.ExceptionHandled = true;
    this.View("Error").ExecuteResult(this.ControllerContext);
}

More information (including how to make it obey customErrors = RemoteOnly) can be found here:

http://blog.dantup.com/2009/04/aspnet-mvc-handleerror-attribute-custom.html

0
source

Source: https://habr.com/ru/post/1785188/


All Articles