Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 640
ilija veselica Avatar asked Nov 30 '22 10:11

ilija veselica


2 Answers

Here's how:

string userId = Membership.GetUser().ProviderUserKey.ToString();
string[] roleNames = Roles.GetRolesForUser(username);
like image 163
Anders Nygaard Avatar answered Dec 10 '22 02:12

Anders Nygaard


Another good one to know is:

bool isAdmin =  Roles.IsUserInRole("Admin");
like image 27
Morph Avatar answered Dec 10 '22 02:12

Morph