开发者

ASP.Net MVC: How to redirect an uathenticated user from any page if they do not satisfy a condition

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. 开发者_JAVA百科

Is this the most sensible way to perform this operation?


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.


I would use attributes on your Actions.

ASP.NET MVC Forms Authentication + Authorize Attribute + Simple Roles

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜