简体   繁体   中英

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

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 perform 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

在您的控制器中,可以将[Authorize]放在您的方法签名之前,如果未经授权,这会将用户重定向到另一个视图。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM