Search code examples
asp.net-mvcmembershipuserid

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 these details?

Thanks,
Ile


Solution

  • Here's how:

    string userId = Membership.GetUser().ProviderUserKey.ToString();
    string[] roleNames = Roles.GetRolesForUser(username);