Search code examples
c#asp.net-mvcasp.net-identityasp.net-roles

Get Role name in IdentityUserRole 2.0 in ASP.NET


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


Solution

  • Ask the RoleMananger?

    RoleManager.Roles.
    // or
    RoleManager.FindByIdAsync()
    // or 
    RoleManager.FindByNameAsync()
    

    You may want to take some time and learn the new security features in Asp.Net Security and Asp.Net Identity.