-
Notifications
You must be signed in to change notification settings - Fork 246
Open
Labels
Description
When creating a new Mvc5 webapp in VS2013 Update 4 with Individual User Accounts. The wizard generated IdentityConfig, AccountController, and ManageController are very different from this sample. This means the logic for seeding doesn't work.
public class MyDbInitializer : DropCreateDatabaseAlways<ApplicationDbContext>
{
protected override void Seed(ApplicationDbContext context)
{
InitializeIdentityForEF(context);
InitializeMyData(context);
}
private void InitializeIdentityForEF(ApplicationDbContext context)
{
var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
string name = "Admin";
string password = "May-27-2015";
//Create Role Admin if it does not exist
if (!RoleManager.RoleExists(name))
{
var roleresult = RoleManager.Create(new IdentityRole(name));
}
//Create admin=Admin with password=123456
var admin = new ApplicationUser();
admin.UserName = name;
admin.Email = "[email protected]";
admin.EmailConfirmed = true;
admin.PhoneNumber = "5551234567";
admin.PhoneNumberConfirmed= true;
var adminresult = UserManager.Create(admin, password);
//Add admin Admin to Role Admin
if (adminresult.Succeeded)
{
var result = UserManager.AddToRole(admin.Id, name);
}
}
private void InitializeMyData(ApplicationDbContext dc)
{
// Custom data initizations
}
}- this sample code given in this example works fine in VS2013 update 4 but doing File New Mvc5 webapp + Individual Accounts no longer works if I attempt to seed with the logic shown above
- cannot login as "Admin" (specifically cannot login as [email protected] on the Login page)
- registering a new user logs in but after logging out I cannot login with the new user credentials