I have the following:
[Authorize(Roles = "admin")]
I am setting it for every action on my controller. However is there some way I can do this globally for the controller?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The attribute works on controllers too.
You can even create a base controller and set the attribute on it (and therefore get the same authorization on all derived controllers)
Update
First question: You can put
[HandleError]in your base controller to get MVC’s error handling in all controllers. I’ve just written a blog entry describing it.Second question: Yes. Put the most specific
[Authorize]attribute on the actions. (for instance authorize “users” in the base controller and “admins” on the Edit action).