You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
publicclassMyDbInitializer:DropCreateDatabaseAlways<ApplicationDbContext>{protectedoverridevoidSeed(ApplicationDbContextcontext){
InitializeIdentityForEF(context);
InitializeMyData(context);}privatevoidInitializeIdentityForEF(ApplicationDbContextcontext){varUserManager=newUserManager<ApplicationUser>(newUserStore<ApplicationUser>(context));varRoleManager=newRoleManager<IdentityRole>(newRoleStore<IdentityRole>(context));stringname="Admin";stringpassword="May-27-2015";//Create Role Admin if it does not existif(!RoleManager.RoleExists(name)){varroleresult= RoleManager.Create(new IdentityRole(name));}//Create admin=Admin with password=123456varadmin=new ApplicationUser();
admin.UserName =name;
admin.Email ="[email protected]";
admin.EmailConfirmed =true;
admin.PhoneNumber ="5551234567";
admin.PhoneNumberConfirmed=true;varadminresult= UserManager.Create(admin, password);//Add admin Admin to Role Adminif(adminresult.Succeeded){varresult= UserManager.AddToRole(admin.Id, name);}}privatevoidInitializeMyData(ApplicationDbContextdc){// 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
The text was updated successfully, but these errors were encountered:
I think I solved this issue for the given seeding values. At minimum, you'd need to initialize the database such that UserName have an email-style string that would be used at logon:
// Username must be an email-style string for Individual Accounts in Identity v2.1+// otherwise you cannot loginvaradmin=new ApplicationUser();
admin.UserName ="[email protected]";
admin.Email ="[email protected]";varadminresult= UserManager.Create(admin, password);
More testing would be needed for other changes but at least logging in via seeded values is possible now.
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.
The text was updated successfully, but these errors were encountered: