authorization - ASP.net MVC: Getting Required Roles for Login? -
Is there a general way to obtain the required role for a particular action?
My problem with detail is that I have 2 roles such as "Users" and "Admin" and an action with:
[Authorize (roles = "admin" )] Admin of Public Sector Administration ...
If the user is not logged in, he takes the login screen. Okay. When a user logs in to the role of "Admin", then all works well, but if the user logs in with "role" then he will display the login screen continuously, in addition he has successfully entered, but definitely Does not have the necessary role.
So it would be good if the login display can show an alert, saying that it is already logged in, but it does not have the necessary rights to view this page. And additionally it can display the necessary roles.
Thank you, Michael
I think this is mainly the default AuthorizeAttribute
From the design page, if fails in any part of the authorization.
You can create a new class that is AuthorizeAttribute
. Then you can override the default behavior and show a different page. See for a great example of this.
Comments
Post a Comment