I'm having trouble working out how to quickly find out yes/no is a username in a role? I've gotten as far as:
Roles.FindUsersInRole("Admin", usersName)
But am a bit stuck, any easy way of doing this?
Definition of user-defined user rolesA role is a database object that groups together one or more privileges and can be assigned to users. A user that is assigned a role receives all of the privileges of that role. A user can have multiple roles. A role hierarchy is also supported.
ASP.NET offers a Roles framework for defining roles and associating them with user accounts. With the Roles framework we can create and delete roles, add users to or remove users from a role, determine the set of users that belong to a particular role, and tell whether a user belongs to a particular role.
The RolePrincipal object's IsInRole(roleName) method calls Roles. GetRolesForUser to get the roles for the user in order to determine whether the user is a member of roleName. When using the SqlRoleProvider , this results in a query to the role store database.
The below returns true or false depending on if the specified user is in the specified role
Roles.IsUserInRole(userName, role)
So, for example, if you wanted to remove a user from a specific role you could use
if (Roles.IsUserInRole(userName, role))
Roles.RemoveUserFromRole(userName, role);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With