An action filter is the way to go in this case:
An action filter that completes an action method. This filter may perform additional processing, such as providing additional data for the action method, checking the return value, or aborting the execution of the action method.
Here is a good MSDN How to: How to create a custom action filter
In your case, you will have something like this:
public class RedirectFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { if (MyService.IsCat==false) return RedirectToAnotherControllerAction(); } }
Then you apply this filter at the controller level (apply to all controller actions)
[RedirectFilterAttribute] public class MyController : Controller {
or per action:
[RedirectFilterAttribute] public ActionResult MyCatAction() {
source share