Skip to content

Instantly share code, notes, and snippets.

@nlivaic
Last active November 27, 2018 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nlivaic/b1bbb39fd7eecd1e7a162b3434f24907 to your computer and use it in GitHub Desktop.
Save nlivaic/b1bbb39fd7eecd1e7a162b3434f24907 to your computer and use it in GitHub Desktop.
Seeding ASP.NET MVC 5 Identity database
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