0

In my asp.net mvc 3 project I have 2 roles "User" and "Admin". How to make if I logged on user I cant see View for Admin role?

2 Answers 2

0

Use [Authorize(Roles="User")] On top of every Controller class you need to.

I personally used this tutorial by Brian Legg

4
  • thank good tutorial, but I found solution. HttpContext.User.IsInRole("Administrators") May 5, 2012 at 14:31
  • that will do exactly the same as that tag I suggested. So you can actually choose between them. I prefer the tag because you can put it on top of your class so you don't have to write any if-clauses. For more control, you could use that code snippet of yours. May 5, 2012 at 14:38
  • you right, but if I log on Admin and I go to Userpanel I watch LogOn form. I dont need it :) May 5, 2012 at 14:46
  • you can always just put the [Authorize] tag on top of every page and on the pages where only admins are allowed put the [Authorize(roles="Admin")] tag May 5, 2012 at 14:53
0

Use the AuthorizeAttribute

1
  • Ignore the version it is exactly the same in newer version. You can navigate to the newer version in the docs and you will find it there. May 5, 2012 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.