Last active
November 27, 2018 12:38
-
-
Save nlivaic/b1bbb39fd7eecd1e7a162b3434f24907 to your computer and use it in GitHub Desktop.
Seeding ASP.NET MVC 5 Identity database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal sealed class Configuration : DbMigrationsConfiguration<_1_Identity.Models.ApplicationDbContext> | |
{ | |
public Configuration() | |
{ | |
AutomaticMigrationsEnabled = true; // Set to true if you want to migrate every time app is restarted. | |
ContextKey = "_1_Identity.Models.ApplicationDbContext"; // This property seems to be mutually exclusive with MigrationsDirectory. | |
MigrationsDirectory = @"DataContexts\IdentityMigrations"; | |
} | |
protected override void Seed(_1_Identity.Models.ApplicationDbContext context) | |
{ | |
// Check if user exists and create a new one. | |
if (!context.Users.Any(u => u.UserName == "admin@a.com")) | |
{ | |
IUserStore<ApplicationUser> store = new UserStore<ApplicationUser>(context); | |
UserManager<ApplicationUser> manager = new UserManager<ApplicationUser>(store); | |
ApplicationUser user = new ApplicationUser { UserName = "admin@a.com", Email = "admin@a.com" }; | |
manager.Create(user, "Password_1"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment