4

How can I get userID and roleID of user that is logged to application? User.Identity doesn't contain these details?

Thanks,
Ile

ilija veselica
  • 9,414
  • 39
  • 93
  • 147

3 Answers3

13

Here's how:

string userId = Membership.GetUser().ProviderUserKey.ToString();
string[] roleNames = Roles.GetRolesForUser(username);
Anders Nygaard
  • 5,433
  • 2
  • 21
  • 30
4

Another good one to know is:

bool isAdmin =  Roles.IsUserInRole("Admin");
Morph
  • 1,719
  • 1
  • 18
  • 23
3

You can use this too :

List<String> roles = Roles.GetRolesForUser().ToList();
Raph
  • 374
  • 1
  • 16