//Create [email protected] with password=Admin@123456 in the Admin role public static void InitializeIdentityForEF(ApplicationDbContext db) { var userManager = HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>(); var roleManager = HttpContext.Current.GetOwinContext().Get <ApplicationRoleManager>(); const string userName = "******"; const string email = "*****@*****.**"; const string password = "******"; const string roleName = "Admin"; const string roleName1 = "Client"; const string roleName2 = "ServiceProvider"; //Create Role Admin if it does not exist var role = roleManager.FindByName(roleName); if (role == null) { role = new ApplicationRole(roleName); var roleresult = roleManager.Create(role); } //Create Role Client if it does not exist var role1 = roleManager.FindByName(roleName1); if (role1 == null) { role1 = new ApplicationRole(roleName1); var roleresult1 = roleManager.Create(role1); } //Create Role ServiceProvider if it does not exist var role2 = roleManager.FindByName(roleName2); if (role2 == null) { role2 = new ApplicationRole(roleName2); var roleresult2 = roleManager.Create(role2); } //Create default admin User var user = userManager.FindByEmail(email); if (user == null) { user = new ApplicationUser { UserName = userName, Email = email }; var result = userManager.Create(user, password); result = userManager.SetLockoutEnabled(user.Id, false); ContactiniContext ctx = new ContactiniContext(); Client cl = new Client(); cl.Email = user.Email; cl.UserName = user.UserName; ctx.Clients.Add(cl); ctx.SaveChanges(); } // Add user admin to Role Admin if not already added var rolesForUser = userManager.GetRoles(user.Id); if (!rolesForUser.Contains(role.Name)) { var result = userManager.AddToRole(user.Id, role.Name); } // Add user admin to Role Client if not already added if (!rolesForUser.Contains(role1.Name)) { var result = userManager.AddToRole(user.Id, role1.Name); } }