ASP.NET Identity add new user and role

var user = new ApplicationUser { Email = "email@gmail.com", UserName = "email@gmail.com" };

var result = await UserManager.CreateAsync(user, "PwD!23");

await RoleManager.CreateAsync(new Microsoft.AspNet.Identity.EntityFramework.IdentityRole { Name = "Admin" });

await UserManager.AddUserToRolesAsync(user.Id, new List<string> { "Admin" });

No Comments

Add a Comment