asp.net mvc - Identity Management in MVC 6 -
i have switched mvc 5 project mvc 6 , having issues identity management.
as part of sign-up process, user selects role saved in userroles table using applicationusermanager.
in mvc 5 version, code in accoutncontroler is
public applicationusermanager usermanager { { return _usermanager ?? httpcontext.getowincontext().getusermanager<applicationusermanager>(); } private set { _usermanager = value; } }
later on in controller...
public async task<actionresult> register(registerviewmodel model) { if (modelstate.isvalid) { var user = new applicationuser() { username = model.email, email = model.email, isregcomplete = true}; identityresult result = await usermanager.createasync(user, model.password); if (result.succeeded) { usermanager.addtorole(user.id, model.role); await signinasync(user, ispersistent: false); if (model.role == "owner") { return redirecttoaction("create", "owners"); } else { return redirecttoaction("create", "servicecompanies"); } } else { adderrors(result); } } // if got far, failed, redisplay form return view(model); }
as there no identityconfig.cs in mvc 6 applicationusermanager go or replaces allow me addtorole()?
cheers, kevin.
i have not been using identity in mvc6 yet, there articles in documentation might you.
Comments
Post a Comment