ASP.net is user in role

試著忘記壹切 提交于 2019-12-07 00:13:26

问题


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?


回答1:


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



回答2:


There is a better way just with

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


来源:https://stackoverflow.com/questions/4244489/asp-net-is-user-in-role

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!