ユーザーが提供した回答が正しくない場合でも、常にパスワードをリセットする PasswordRecovery コントロールを使用しています。「OnAnswerLookupError」イベントを発生させていないようです。誰かがこれに遭遇したことがありますか、または私が間違っていることを知っていますか?
非常に簡単なコードです。以下に貼り付けます。唯一の実際のカスタマイズは、ロックアウトされたユーザーがパスワードをリセットできるようにすることです (クライアントからの要求に従って)。
<%@ Page Title="Password Recovery" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="PasswordRecovery.aspx.cs" Inherits="OurApp.UI.Account.PasswordRecovery" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Password Recovery
</h2>
<p>
Follow instructions to reset your password.
</p>
<asp:Label ID="lblMessage" runat="server" Font-Bold="true" ForeColor="red" />
<asp:PasswordRecovery SuccessText="Your password was successfully reset and emailed to you."
OnAnswerLookupError="UserLookupError"
OnUserLookupError="UserLookupError"
OnVerifyingUser="UserCheck"
QuestionFailureText="Incorrect answer. Please try again." runat="server" ID="RecoveryInput"
UserNameFailureText="Username not found."
OnSendingMail="RecoveryInput_SendingMail">
<MailDefinition IsBodyHtml="false" BodyFileName="~/Account/email.ascx"
From="DoNotReply@ourdomain.com"
Subject="Our App - Password Reset"
Priority="High">
</MailDefinition>
<UserNameTemplate>
<asp:Panel ID="pnl1" runat="server" DefaultButton="submit">
<dl>
<dd>User Name</dd>
<dd>
<asp:TextBox ID="Username" runat="server" AUTOCOMPLETE="OFF" />
</dd>
<dt></dt>
<dd>
<asp:Button ID="submit"
CausesValidation="true"
ValidationGroup="PWRecovery"
runat="server"
CommandName="Submit"
Text="Submit" />
</dd>
<dt></dt>
<dd>
<p class="Error"><asp:Literal ID="ErrorLiteral"
runat="server"></asp:Literal>
</p>
</dd>
</dl>
</asp:Panel>
</UserNameTemplate>
<QuestionTemplate>
<asp:panel ID="pnl1" runat="server" DefaultButton="submit">
Hello
<asp:Literal runat="server" ID="personname" />,
<p>
You must answer your recovery question in order to have a new email sent to you.
</p>
<dl>
<dt>Question:</dt>
<dd>
<asp:Literal runat="server" ID="Question" />
</dd>
<dt></dt>
<dt>Answer:</dt>
<dd>
<asp:TextBox runat="server" ID="Answer" AUTOCOMPLETE="OFF" />
</dd>
<dt></dt>
<dd>
<asp:Button runat="server" ID="submit"
Text="Submit" CommandName="submit" />
</dd>
<dt></dt>
<dd>
<p class="Error">
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
</p>
</dd>
</dl>
</asp:panel>
</QuestionTemplate>
</asp:PasswordRecovery>
<asp:HyperLink NavigateUrl="~/Account/Login.aspx" runat="server">Login</asp:HyperLink>
</asp:Content>
public partial class PasswordRecovery : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblMessage.Text = string.Empty;
}
protected void UserCheck(object sender, EventArgs e)
{
MembershipUser mu = Membership.GetUser(RecoveryInput.UserName);
if (mu == null)
{
UserLookupError(sender, e);
return;
}
if (mu.IsLockedOut)
{
//UserLookupError(sender, e);
//return;
mu.UnlockUser();
}
}
protected void UserLookupError(object sender, EventArgs e)
{
lblMessage.Text = "There was a problem resetting your password. Please contact your Administrator or Account Executive for assistance.";
}
protected void RecoveryInput_SendingMail(object sender, MailMessageEventArgs e)
{
try
{
MembershipUser mu = Membership.GetUser(RecoveryInput.UserName);
mu.Comment = "MustChangePassword";
Membership.UpdateUser(mu);
}
catch (Exception ex)
{
Utilities.ErrorHandling.HandleError(ex);
lblMessage.Text = "There was a problem resetting your password. Please contact your administrator.";
}
}
}