When the user sets the password question and answer, the user's password is verified. When the password is incorrect, an error is returned, prompting the user. If the password is correct, navigate to the password setting Question and Answer page.
Here, four pages are used, the template page (Site. master), user information page (LogOnUserControl. ascx), set the password Question and Answer page (ChangePasswordQuestionAndAnswer. aspx), verify the user password page (ValidationUserPassword. ascx ).
Let's take a look at SIte. Master. This page is nested with LogOnUserControl. ascx,
<% Html. RenderPartial ("LogOnUserControl"); %>
LogOnUserControl. ascx has a navigation that allows users to set password questions and answers.
<% = Html. actionLink ("set password Questions and Answers", "ValidationUserPassword", "Account", new {height = "230", width = "300", modal = true }, new {@ class = "thickbox", title = "verify User Password"}) %>
I will use thiskbox to activate and verify the user password page ValidationUserPassword. ascx.
ValidationUserPassword. ascx code
Code
<% @ Control Language = "C #" Inherits = "System. Web. Mvc. ViewUserControl <BobDongCommunity. Modules. Account. ViewModels. ValidationUserPassword>" %>
<Div id = "passwordmain">
<% Using (Ajax. BeginForm ("ValidationUserPassword", "Account", new AjaxOptions {UpdateTargetId = "passwordmain "}))
{%>
<Fieldset>
<Legend> User Password </legend>
<Div class = "editor-label">
<% = Html. LabelFor (model => model. Password) %>
</Div>
<Div class = "editor-field">
<% = Html. PasswordFor (model => model. Password) %>
<% = Html. ValidationMessageFor (model => model. Password) %>
</Div>
<P>
<Input id = "Submit" type = "submit" value = "Logon"/>
</P>
</Fieldset>
<% }%>
</Div>
The following code processes ValidationUserPassword. aspx background Action:
Code
1 [Authorize]
2 [AcceptVerbs (HttpVerbs. Post)]
3 public ActionResult ValidationUserPassword (ValidationUserPassword model)
4 {
5 If (modelstate. isvalid)
6 {
7 if (membershipservice. validateuser (user. Identity. Name, model. Password ))
8 {return JavaScript ("document. Location = '/account/changepasswordquestionandanswer '");
9 // return redirecttoaction ("changepasswordquestionandanswer ");
10}
11 else
12 {
13 modelstate. addmodelerror ("password", "Incorrect password. Please try again! ");
14}
15}
16 return View ();
17}
18
Running result description:
First activate the authentication password thickbox layer and enter the password
The password is incorrect. The expected result is displayed.
When the password is correct, we get this result.
For this reason, AJAX is used for password verification. When the password is correct, it updates ChangePasswordQuestionAndAnswer. aspx to ValidationUserPassword. ASPX.
Now the problem arises. Instead of updating it, I directly jump to ValidationUserPassword. ASPX, just like this.
After the problem is solved, return JavaScript ("document. location = '/Account/logon'") from the background '");
In this way, the original layer will not be updated.