Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
Obtenga el nombre del rol en IdentityUserRole 2.0 en ASP.NET

Antes de la actualización de los dll en Entity Framework, pude hacer esto

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

Ahora, solo puedo hacer r.RoleId, y no puedo encontrar una manera de recuperar el nombre de esa ID de rol. Estoy usando esto en mis controladores y en mi clase AuthorizeAttribute.

¿Puede alguien ayudarme aquí?

Saludos

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Prueba esto

 string id = UserManager.FindByEmail(model.Email).Id; IList<string> roleNames=UserManager.GetRoles(id);
over 4 years ago · Santiago Trujillo Report

0

Preguntar al RoleManager ?

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

Es posible que desee tomarse un tiempo y aprender las nuevas características de seguridad en Asp.Net Security y Asp.Net Identity .

over 4 years ago · Santiago Trujillo Report

0

Acabo de tener casi exactamente el mismo problema y lo resolví así:

 public class UserRole : IdentityUserRole { public virtual Role Role { get; set; } // add this to see roles public virtual User User { get; set; } // add this to see users }

Ahora su código original user.Roles.Where(r => r.Role.Name == "Admin").FirstOrDefault(); funcionará, lo que podría ser útil si no tiene fácil acceso a RoleManager por cualquier motivo.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!