且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取任何用户的所有角色(是的,不是当前登录的)

更新时间:2023-11-30 10:27:16

使用的Roles.GetRolesForUser()方法的 https://msdn.microsoft.com/en-us/library/8h930x07(v = vs.110)的.aspx

Use the Roles.GetRolesForUser() method https://msdn.microsoft.com/en-us/library/8h930x07(v=vs.110).aspx

string[] rolesArray = Roles.GetRolesForUser("username"); 

通过字符串是载于ASPNETDB的用户的用户名。

With the string being the User Name of the user as contained in the aspnetdb.

如果你想使用GUID找到,你可以尝试以下方法:

If you want to find by using a guid, you could try the following:

Guid userId; // ID of user - you can populate this somehow
MembershipUser memUser = Membership.GetUser(userId);
string[] roles = Roles.GetRolesForUser(memUser.UserName);