开发者

ASP.NET MVC2 Membership: How to get userID and roleID of logged user?

开发者 https://www.devze.com 2022-12-29 06:03 出处:网络
How can I get userID and roleID of user that is logged to application? User.Identity doesn\'t contain the开发者_运维技巧se details?

How can I get userID and roleID of user that is logged to application? User.Identity doesn't contain the开发者_运维技巧se details?

Thanks,

Ile


Here'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();
0

精彩评论

暂无评论...
验证码 换一张
取 消