Search code examples
asp.netasp.net-core-mvccreateuser

How to create New user using Asp.net mvc identity out side from Accountcontroller?


I am trying in my applicaton to add user outside from Registriation so outside Accountcontrol and i tried to add manually to database but it does not work also i need to take the hashpassword


Solution

  • here is the answer of my question: just create a new 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);