c# - SendTwoFactorCodeAsync returning 'UserId not found' after successful login, using SignManager with dependency -
i using signinmanager , authenticationmanager through dependency injection. working fine except sendtwofactorcodeasync
here code:
utilityconfig
container.registertype<applicationsigninmanager>(); container.registertype<applicationusermanager>();
account controller
var myuser = await usermanagerservice.value.findasync(model.mobile, model.password); if (myuser != null) { var result = await signinmanager.value.passwordsigninasync(model.mobile, model.password, false, shouldlockout: false); switch (result) { case signinstatus.success: { //success code } case signinstatus.requiresverification: { var code = await usermanagerservice.value.generatetwofactortokenasync(myuser.id, configurationmanager.appsettings["phonecodeprovider"]); var send = await signinmanager.value.sendtwofactorcodeasync(configurationmanager.appsettings["phonecodeprovider"]); //here throughing exception if (send) { smshelper.value.sendsmsbysmsbatch(user.username, constant.instance().productname, myuser.username, "code " + code, true); return redirecttoaction("twofactorcode", new { provider = configurationmanager.appsettings["phonecodeprovider"], returnurl = returnurl, rememberme = false }); } } break; --------------- }
also tried this:
var userid = await signinmanager.value.getverifieduseridasync(); // returning 0 var user = await usermanagerservice.value.findbyidasync(userid); if (user != null) { var code = await usermanagerservice.value.generatetwofactortokenasync(myuser.id, configurationmanager.appsettings["phonecodeprovider"]); var send = await signinmanager.value.sendtwofactorcodeasync(configurationmanager.appsettings["phonecodeprovider"]); //here throughing exception if (send) { smshelper.value.sendsmsbysmsbatch(user.username, constant.instance().productname, user.username, "your security code " + code, true); return redirecttoaction("twofactorcode", new { provider = configurationmanager.appsettings["phonecodeprovider"], returnurl = returnurl, rememberme = false }); } }
strange thing on first try issue , on second try works fine (return results perfectly) .. again logout , try .. first time issue second try works .
not able track reason of failure, can best way solve
i exact same error. tried adding case signinstatus.requiresverification: thread.sleep(500) see if delay no avail.
it requires redirect sendtwofactorcodeasync checks see if request.isauthernticated. request not, there valid log in.
it bug , should reported on github
Comments
Post a Comment