开发者

ASP.NET MVC 3 - Get Controller and Action and Perform Redirect from Application_OnAuthenticateRequest Method

开发者 https://www.devze.com 2023-03-24 07:52 出处:网络
I have implemented the Application_OnAuthenticateRequest method in my Global.asax class in my ASP.NET MVC 3 application. When a user hits a page on my application, I load the user and verify their acc

I have implemented the Application_OnAuthenticateRequest method in my Global.asax class in my ASP.NET MVC 3 application. When a user hits a page on my application, I load the user and verify their account status. When their account status does not match the valid account statuses, I want to redirect that user to a controller/action to pe开发者_C百科rform additional actions.

The problem I am having is that I need to get the controller/action from the request to ensure that an infinite loop of redirects doesn't occur. I also am not sure of the best way to handle the redirect in this method to my new controller/action.

Any way to do this?


It is better to put your logic inside a custom Authroze Filter instead of Application_OnAuthenticateRequest method. Check this link


In your controller you could put [Authorize] before your method signature and this will redirect the user to another view if they are not authorized.


How about a Custom Method to authorize the user and Try/Catch? In "Catch" send him to the View you want.

0

精彩评论

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