ASP.NET MVC2 Membership: How to get userID and roleID of logged user?
How can I get userID and roleID of user that is logged to application? User.Identity
doesn't contain the开发者_运维技巧se details?
Thanks,
IleHere's how:
string userId = Membership.GetUser().ProviderUserKey.ToString();
string[] roleNames = Roles.GetRolesForUser(username);
Another good one to know is:
bool isAdmin = Roles.IsUserInRole("Admin");
You can use this too :
List<String> roles = Roles.GetRolesForUser().ToList();
精彩评论