ASP.NET MVC2 membership: how to get the user ID and roleID of the registered user?

How can I get the user ID and roleID of the user registered in the application? User.Identity does not contain this data?

Thanks,
Ile

+4
source share
3 answers

Here's how:

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

Another good way to find out:

 bool isAdmin = Roles.IsUserInRole("Admin"); 
+4
source

You can also use this:

 List<String> roles = Roles.GetRolesForUser().ToList(); 
+3
source

Source: https://habr.com/ru/post/1308747/


All Articles