我正在尝试在Registriation之外添加用户,因此在Accountcontrol之外,我尝试手动添加到数据库但是它也不起作用我也需要使用hashpassword
答案 0 :(得分:3)
这是我的问题的答案: 只需创建一个新的applicationdfcontext:)
var store = new UserStore<ApplicationUser>(new ApplicationDbContext());
ApplicationUserManager _userManager = new ApplicationUserManager(store);
var manger = _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
var user = new ApplicationUser() { Email = aspNetUsers.Email, UserName = aspNetUsers.UserName };
var usmanger= manger.Create(user, aspNetUsers.PasswordHash);