tags:

views:

129

answers:

2

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);
    }   
}
+1  A: 

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.

Mark Dickinson
+2  A: 

Try this:

filterContext.Result = new RedirectToRouteResult(
    new System.Web.Routing.RouteValueDictionary {
        {"controller", "Error"}, {"action", "ServiceNotFound"}
    }
);
eu-ge-ne