c# - Doesn't Redirect to ForgotPasswordConfirmation -
this question has answer here:
[authorize] public class accountcontroller : controller { [allowanonymous] public actionresult login(string returnurl) { viewbag.returnurl = returnurl; return view(); } // // post: /account/login [httppost] [allowanonymous] [validateantiforgerytoken] public async task<actionresult login(loginviewmodel model, string returnurl) { if (modelstate.isvalid) { // find user username first var user = await usermanager.findbynameasync(model.email); if (user != null) { var validcredentials = await usermanager.findasync(model.email, model.password); // when user lockedout, check done ensure if credentials valid // user can not login until lockout duration has passed if (await usermanager.islockedoutasync(user.id)) { modelstate.addmodelerror("", string.format("invalid credentials. please try again, or contact support", 60)); } // if user subject lockouts , credentials invalid // record failure , check if user lockedout , display message, otherwise, // display number of attempts remaining before lockout else if (await usermanager.getlockoutenabledasync(user.id) && validcredentials == null) { // record failure may cause user locked out await usermanager.accessfailedasync(user.id); string message; if (await usermanager.islockedoutasync(user.id)) { message = string.format("invalid credentials. please try again, or contact support", 60); } else { int accessfailedcount = await usermanager.getaccessfailedcountasync(user.id); int attemptsleft = (5 - accessfailedcount); message = string.format("invalid credentials. please try again, or contact support.", attemptsleft); } modelstate.addmodelerror("", message); } else if (validcredentials == null) { modelstate.addmodelerror("", "invalid credentials. please try again, or contact support."); } else { await signinasync(user, model.rememberme); // when token verified correctly, clear access failed count used lockout await usermanager.resetaccessfailedcountasync(user.id); return redirecttolocal(returnurl); } } else { modelstate.addmodelerror("", string.format("invalid credentials. please try again, or contact support", 60)); } } // if got far, failed, redisplay form return view(model); } [httppost] [allowanonymous] [validateantiforgerytoken] public async task<actionresult forgotpassword(forgotpasswordviewmodel model) { if (modelstate.isvalid) { var user = await usermanager.findbynameasync(model.email); if (user == null || !(await usermanager.isemailconfirmedasync(user.id))) { // don't reveal user not exist or not confirmed //modelstate.addmodelerror("", "the user either not exist or not confirmed."); return redirecttoaction("forgotpasswordconfirmation", "account"); } else { var code = await usermanager.generatepasswordresettokenasync(user.id); var callbackurl = url.action("resetpassword", "account", new { userid = user.id, code = code }, protocol: request.url.scheme); string data = system.io.file.readalltext(server.mappath(@"~/documents/email_password_reset.txt")); aspnetuser ouser = dbportal.aspnetusers.find(user.id); // can't use string.format becuase of css data = data.replace("{0}", ouser.name); // user name data = data.replace("{1}", callbackurl); // url click data = data.replace("{2}", datetime.now.year.tostring()); // copyright year await usermanager.sendemailasync(user.id, "reset password", data); return redirecttoaction("forgotpasswordconfirmation", "account"); } } // if got far, failed, redisplay form return view(model); } // // get: /account/forgotpasswordconfirmation [allowanonymous] public async task<actionresult forgotpasswordconfirmation() { return view(); } }
the above should redirect user forgotpasswordconfirmation when entered theit email. instead sends user login following url
login?returnurl=%2faccount%2fforgotpasswordconfirmation
i changed according duplicate post
i cannot figure out why
there issues if , when have async method redirecting synchronous method. try changing forgotpasswordconfirmation() method async:
public asycn task<actionresult> forgotpasswordconfirmation()
also, see this: mvc4 .net 4.5 async action method not redirect
Comments
Post a Comment