Dave Gordon
Dave Gordon

Reputation: 1835

I have roles Seeded - but Roles.GetAllRoles doesn't work?

Ok I have seeded some roles which can be found in the SQL database in the table AspNetRoles and the users can be found AspNetUsers.

I have also found a bunch of aspnet_ tables (I think they are old WebForm ones). Within a view I am calling @Roles.GetAllRoles() which is returning no results. the aspnet_Roles table has no records. So it may be checking there. But that seems unlikely as the seeded roles are being created thusly:

 var roleManager = new RoleManager<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
        if (!roleManager.RoleExists("Member"))
              roleManager.Create(new IdentityRole("Member"));

Which in my little knowledge of MVC5 would suggest that Roles.GetAllRoles() would return the correct result.

I am using this @model EUWebRole.Models.IdentityManager also tried ApplicationUser with no change in results.

So to the questions:

1) How do I get the list of Roles? 2) If I am using the wrong "tables" how do I set it so that it is using the correct tables?

Any ideas would be greatly appreciated.

Upvotes: 0

Views: 556

Answers (1)

Erik Philips
Erik Philips

Reputation: 54618

You're aspnet_tables are old from either the default MembershipProvider or the SimpleMembershipProvider (either way it doesn't matter they should be removed).

MVC 5 uses Identity 2.0 by default. If you need to do anything with roles you need to use the RoleManager.

Upvotes: 3

Related Questions