如何获取登录到应用程序的用户的用户 ID 和角色 ID?User.Identity不包含这些细节?
谢谢,
伊莱
Here's how:
string userId = Membership.GetUser().ProviderUserKey.ToString();
string[] roleNames = Roles.GetRolesForUser(username);
另一个好消息是:
bool isAdmin = Roles.IsUserInRole("Admin");
您也可以使用它:
List<String> roles = Roles.GetRolesForUser().ToList();