4

如何获取登录到应用程序的用户的用户 ID 和角色 ID?User.Identity不包含这些细节?

谢谢,
伊莱

4

3 回答 3

13

Here's how:

string userId = Membership.GetUser().ProviderUserKey.ToString();
string[] roleNames = Roles.GetRolesForUser(username);
于 2010-05-04T10:35:28.343 回答
4

另一个好消息是:

bool isAdmin =  Roles.IsUserInRole("Admin");
于 2010-05-04T11:28:04.067 回答
3

您也可以使用它:

List<String> roles = Roles.GetRolesForUser().ToList();
于 2012-04-13T12:54:59.880 回答