System.Web.Security
is the old ASP.NET Membership framework. ASP.NET Identity is in the namespace Microsoft.AspNet.Identity
. Use a RoleManager
to create roles, and a UserManager
to add users to roles.
using (var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context))
{
roleManager.Create(new IdentityRole("Administrator"));
}
using (var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context)))
{
var user = new ApplicationUser { UserName = "admin" };
userManager.Create(user, "admin321");
userManager.AddToRole(user.Id, "Administrator");
}