I am working on a MVC using asp.net core where I have created a global filter to handling exceptions. Its handling exceptions but not redirecting to view(Error.cshtml) which is in Shared folder.
Below is my code:
public void OnException(ExceptionContext filterContext)
{
if (filterContext.ExceptionHandled)
{
return;
}
Exception e = filterContext.Exception;
filterContext.ExceptionHandled = true;
string action = filterContext.RouteData.Values["action"].ToString();
string controller = filterContext.RouteData.Values["controller"].ToString();
filterContext.Result = new ViewResult()
{
ViewName = "/Error" // also tried with "Error" and "~/Error"
};
}
I hope this works for you