views:

198

answers:

1

Hi everyone!

I'm having a huge problem in understanding Membership with MVC. We have in our project controllers named "Admin" and "SuperAdmin" and they are restricted to some users.

Do I have to use the Authorize Roles attribute on each Action or can I use a ActionFilter to check if an user can view a certain page?

And if I have to user Roles attribute, do I have to configure each user on the ASP.NET Configuration tool? For example, "SuperAdmin" will be only a few users (around 3 at top), making easy to use ASP.NET Configuration tool and tells it who these users are. But "Admin" users will be many more... how can I configure them?

I'm totally lost!

I need a great clarifying on that!

Thanks a lot!!!

+2  A: 

You can apply the AuthorizeAttribute to controllers as well as actions. If you apply it to the controller, each method will have its access restricted with respect to the attribute. You can also apply another instance of the attribute to individual actions to further restrict access if necessary based on other roles. You will need to put the individual users in their roles for them to have access to role-controlled controllers/actions.

tvanfosson
@tvanfosson - But, in a case of "Admin" users (which I don't know how many of them will exist), do I have to configure every single one to "Admin" role in Configuration tool?
AndreMiranda
@AndreMiranda - It's either configure them in the configuration tool, or build your own user administration system so the application SuperAdmin's can go in and do it themselves.
mannish
@andreMiranda -- I usually role my own RoleProvider and set up the management of roles as part of the administrator section of the application as @mannish suggests. If you use the WindowsTokenRoleProvider, you could manage this with AD groups offline. Depends on whether that's available to your app or not.
tvanfosson
ok! I will try the answers from you! :-) Thanks a lot!
AndreMiranda