且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP MVC:如何从ApplicationUser获得角色

更新时间:2023-02-25 18:57:12

您可以通过使用的UserManager获得用户并分配角色。

You can get user and assigned roles by using UserManager.

var userManager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();

,然后你可以得到你的用户喜欢你已经做了,也可以通过调用方法getRoles获取特定的用户角色

and then you can get your user like you already did, and also you can get roles for particular user by calling GetRoles method

userManager.GetRoles(userId);