Get Role name in IdentityUserRole 2.0 in ASP.NET

MarBVI picture MarBVI · Jun 5, 2015 · Viewed 15.8k times · Source

Before the update of the dll's in the Entity Framework i was able to do this

user.Roles.Where(r => r.Role.Name == "Admin").FisrtOrDefault(); 

Now, i can only do r.RoleId, and i can't find a way to retreive the name of thar Role Id. I'm using this in my controllers and in my AuthorizeAttribute class.

Can someone help me here?

Regards

Answer

Neeraj Singh picture Neeraj Singh · Jun 30, 2016

Try this

string id = UserManager.FindByEmail(model.Email).Id;
IList<string> roleNames=UserManager.GetRoles(id);