views:

16

answers:

2

I need to redirect any Authenticated user to a specific page if they do not satisfy a condition.

I have implemented a base controller from which all controllers inherit. In its OnActionExecuting override I plan to perform my test for the condition and redirect to the specific action if the condition is not met.

Is this the most sensible way to perform this operation?

A: 

You could do it that way if you're planning on every action being screened or you could go the route of using custom Action Filters a la the HandleError filter.

With filters you have access to the entire request stream and you can perform different actions. You can stack filters as well and even order them so they're executed in a specific order. Action filters can be applied at the class level too which means it will be applied to every action for you.

Erik Noren
I can see the advantages of Custom Action Filters Attributes but how can I use RedirectToAction inside the OnActionExecuting override of the ActionFilterAttribute?
Pones
filterContext.HttpContext.Response.Redirect(errorUrl, true); Is this what you're asking?
Erik Noren
Ultimately thats what i have ended up doing, thanks.
Pones