简体   繁体   中英

ASP.net is user in role

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?

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);

There is a better way just with

if (Roles.IsUserInRole("Admin")) 
{
    // Code Here... 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM