シナリオを機能させるために助けを求めたかっただけですか?PasswordResetTokenを使用してUserNameを取得したい。
これが私のシナリオです。
- 私のウェブサイトにパスワードを忘れた場合の機能があり、パスワードを再設定した電子メールでパスワードの変更をユーザーに送信します。
- passwordresettoken文字列のみを送信したかったのです。
ユーザーがリンクをクリックしたとき。request ["token"]にクエリを実行してユーザー名を取得し、ユーザーがパスワードと自動ログインを変更できるようにします。
これは以下の私のコードです:
public ActionResult ChangePassword() { ChangePasswordModel model = new ChangePasswordModel(); string token=string.Empty; try { token = Request["token"].ToString(); int userId = WebSecurity.GetUserIdFromPasswordResetToken(token); if (userId > 0) { //Get the user object by (userid) //??????????????????? //??????????????????? } else { throw new Exception("The change password token has expired. Please go to login page and click forgot password again."); } } catch { model.HasError = true; ModelState.AddModelError("", "The change password token has expired. Please go to login page and click forgot password again."); } return View(model); }
前もって感謝します。