简体   繁体   中英

PasswordReset with WebSecurity in WebMatrix not working

Possible duplicate Webmatrix WebSecurity not authenticating

This is my PasswordReset.cshtml page :

@{
Layout="Layout.cshtml";
var uID = "";
var newPass = "";
var confirmPass = "";
var token = "";
if(IsPost){
uID = Request.Form["userID"];
newPass = Request.Form["newPassword"];
confirmPass=Request.Form["confirmPassword"];
token=WebSecurity.GeneratePasswordResetToken(uID, 5);
WebSecurity.ResetPassword(token, newPass);
}else{
      Response.Redirect("Default");
      }
}

Now, the error message goes like this :

Server Error in '/' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'userID' does not exist in the current context

Source Error:

Line 10: newPass = Request.Form["newPassword"];

Line 11: confirmPass = Request.Form["confirmPassword"];

Line 12: token = WebSecurity.GeneratePasswordResetToken(userID, 5);

Line 13: WebSecurity.ResetPassword(token, newPass); 

I think the code is correct, but I can't figure out the cause of the error. Please help.

That variable doesn't exist in the context above. You're storing your user Id from Request.Form in uId , so did you mean:

WebSecurity.GeneratePasswordResetToken(uID, 5);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM