C# – How to redirect from OnActionExecuting in Base Controller

asp.net-mvcconactionexecuting

I have tried two ways: Response.Redirect() which does nothing, as well as calling a new method inside of the Base Controller that returns an ActionResult and have it return RedirectToAction()… neither of these work.

How can I do a redirect from the OnActionExecuting method?

Best Answer

 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
    ...
    if (needToRedirect)
    {
       ...
       filterContext.Result = new RedirectResult(url);
       return;
    }
    ...
 }