0

I need to implement one website and in this website i want to give access to users on the basis of there roles. I used Roles and Membership, but i found its based on folder. I want form based authentication. Is there any tool for this.

Calum
  • 1,889
  • 2
  • 18
  • 36
Sagar
  • 29
  • 1
  • 7
  • Take a look at this thread, it should help you: http://stackoverflow.com/questions/4280184/asp-net-membership-roles-web-config-settings – Brandon Spilove May 20 '14 at 13:26
  • thanks for your reply. But its not my requirement.In my website there are some menus i want to display menus to users based on there role. – Sagar May 21 '14 at 04:31

1 Answers1

1

In your code you can check a user's role membership, something like this:

if (User.IsInRole("admins")) {
    //display the admin menu
} else {
    //display the non-admin menu
}
Brandon Spilove
  • 1,529
  • 1
  • 10
  • 15
  • But if i have more than 10 roles then i need to check for every role and for every role i need to check for every form ... – Sagar May 22 '14 at 10:30
  • I'm not following exactly what you are trying to do. There are 2 ways to check that a user is in a role. You can use User.IsInRole("rolename") or you can use Roles.GetRolesForUser() which will give you a string array you can check if your role is in there. If you have 10 roles and need to do something different based on each role, then yeah you'll need to check every role. – Brandon Spilove May 22 '14 at 13:02