Creating Roles in Asp.net Identity MVC 5

前端 未结 11 1368
情深已故
情深已故 2020-12-02 05:09

There is very little documentation about using the new Asp.net Identity Security Framework.

I have pieced together what I could to try and create a new Role and add

11条回答
  •  情深已故
    2020-12-02 05:39

    Here we go:

    var roleManager = new RoleManager(new RoleStore(new ApplicationDbContext()));
    
    
       if(!roleManager.RoleExists("ROLE NAME"))
       {
          var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
          role.Name = "ROLE NAME";
          roleManager.Create(role);
    
        }
    

提交回复
热议问题