c# - Seeding database with admin user--but he can't log in -


i creating mvc application , want seed database single admin user, have ability create other users. i'm doing follows:

    applicationuser admin = new applicationuser     {         username = "whatever",         email = "whatever@mailinator.com",         emailconfirmed = true     };      string pwd = "password";      var chkuser = await _usermanager.createasync(admin, pwd);     if (chkuser.succeeded)     {         await _usermanager.addtoroleasync(admin, constants.roles.administrator);     } 

this creates user in database, expected. when try login user, fail. screenshot of failure

this puzzling me, because use exact same code when users register through gui, there working fine.

// post: /account/register [httppost] [allowanonymous] [validateantiforgerytoken] public async task<iactionresult> register(registerviewmodel model, string returnurl = null) {     viewdata["returnurl"] = returnurl;     if (modelstate.isvalid)     {         var user = new applicationuser { username = model.email, email = model.email };         var result = await _usermanager.createasync(user, model.password);         if (result.succeeded)         {            bunch of stuff regarding sending confirmation email             return redirecttolocal(returnurl);         }         adderrors(result);     }      // if got far, failed, redisplay form     return view(model);' 

in both methods, variable _usermanager of type usermanager<applicationuser> , supplied method through dependency injection.

when user logs in, looked username. users created through gui, email address , username identical. "seed" user has username different email address. when tries login, system tries find user username matches seed user's email address--and fails.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -