How-to access RedirectToAction from a custom ActionFilter ?
public class ExceptionHandlingFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (filterContext.Exception != null && !filterContext.ExceptionHandled)
{
filterContext.ExceptionHandled = true;
// HERE : RedirectToAction("ServiceNotFound","Error");
}
base.OnActionExecuted(filterContext);
}
}
Try this:
filterContext.Result = new RedirectToRouteResult(
new System.Web.Routing.RouteValueDictionary {
{"controller", "Error"}, {"action", "ServiceNotFound"}
}
);
You don't really. You can either use a RedirectResult or RedirectToRouteResult. If you are looking at redirecting away based on authentication, you should consider that a Controller is an ActionFilter, so you can probably inherit this basic behaviour from a base controller class. Just override the OnActionExecuting method in base class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With