开发者

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 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜