-2

How can I add roles in a empty mvc 5 project?

I searched on google but I don't found a tutorial for an empty project.

Can someone give me a link to a tutorial or help me here ?

Ursaciuc Adrian
  • 37
  • 1
  • 2
  • 10

1 Answers1

0

This way:

var roleManager = new RoleManager<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
if (!roleManager.RoleExists("RoleName"))
{
      var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
      role.Name = "RoleName";
      roleManager.Create(role);
}
Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110