I have a custom exception filter that I call by adding the [CustomExceptionFilter] attribute to my class. It works as I would like, but if the action method returns a partial view (via an ajax request), an exception (which is basically a redirect to an unauthorized page) loads a partial view using this page. Is there a way to make it reload the "parent "URL?
Here is the code for a custom exception filter
public class CustomExceptionFilter : FilterAttribute, IExceptionFilter { public void OnException(ExceptionContext filterContext) { if (filterContext.Exception.GetType() == typeof(CustomSecurityException)) { filterContext.ExceptionHandled = true; RequestContext rc = new RequestContext(filterContext.HttpContext, filterContext.RouteData); string url = RouteTable.Routes.GetVirtualPath(rc, new RouteValueDictionary(new { Controller = "NoAccess", action = "Index", message = filterContext.Exception.Message })).VirtualPath; filterContext.HttpContext.Response.Redirect(url, true); } } }
filter asp.net-mvc custom-exceptions
Kyle
source share