使用Entity Framework初始化程序初始化IdentityUser

时间:2016-01-26 06:40:20

标签: entity-framework entity-framework-6 code-first

由于密码已加密,如何使用Seed方法初始化用户。

1 个答案:

答案 0 :(得分:1)

您可以初始化Usermanager对象并创建用户。

protected override void Seed(ApplicationDbContext context)
{
     var userStore = new UserStore<ApplicationUser>(context);
     var userManager = new UserManager<ApplicationUser>(userStore);
     var admin = new ApplicationUser { UserName = "your username", Email = "your email" };
     userManager.Create(admin, "your password");
}