views:

563

answers:

1

Simple question. How do I go about overriding the OnResultExecuting method in my Controller and force a different ActionResult instead?

Sample code is below. Currently the original ActionResutl continues to execute and my new RedirectResult is ignored.

RedirectResult redirectResult = new RedirectResult("http://www.google.com");
filterContext.Result = redirectResult;
base.OnResultExecuting(filterContext);
+1  A: 

It would be possible if you override the OnActionExecuted method.

Example:

protected override void OnActionExecuted(ActionExecutedContext filterContext)
  {
      filterContext.Result = new RedirectResult("http://google.com");
      base.OnActionExecuted(filterContext);
  }
Marwan Aouida