我正在尝试对用户管理页面进行编码,但Membership
API在直接更新到例如密码问题。我可以使用控制吗?
答案 0 :(得分:1)
回答有关更新密码问题的具体问题:
对于.aspx页面或.ascx控件,您可以使用以下标记:
<p style="margin-bottom: 20px;">
A security question is used to assist you in logging in.
Because of this, we ask that you provide your password for confirmation
of wanting to change the security question associated with your account.
</p>
<ul class="formFields">
<li>
<label>
Question</label><asp:TextBox ID="uxNewQuestion" runat="server" />
<asp:RequiredFieldValidator ID="uxNewRequired"
runat="server" ControlToValidate="uxNewQuestion"
ErrorMessage="New Question is required."
ToolTip="New Question is required."
ValidationGroup="ChangeQuestion">*</asp:RequiredFieldValidator>
</li>
<li>
<label>
Answer</label><asp:TextBox ID="uxNewAnswer" runat="server" />
<asp:RequiredFieldValidator ID="uxConfirmRequired"
runat="server" ControlToValidate="uxNewAnswer"
ErrorMessage="Must Confirm Question"
ToolTip="Must Confirm Question" ValidationGroup="ChangeQuestion">
*</asp:RequiredFieldValidator>
</li>
<li>
<label>
Your Password:</label>
<asp:TextBox ID="uxPassword" runat="server" TextMode="Password">
</asp:TextBox>
<asp:RequiredFieldValidator ID="uxPasswordRequired"
runat="server" ControlToValidate="uxPassword"
ErrorMessage="Must Provide Correct Password"
ToolTip="Must Provide Correct Password"
ValidationGroup="ChangeQuestion">*</asp:RequiredFieldValidator>
</li>
</ul>
<p>
<asp:Button ID="uxSave" runat="server" Text="Save Security Question"
OnClick="uxSave_Click"
ValidationGroup="ChangeQuestion" />
<asp:Button ID="Button1" runat="server" Text="Cancel"
OnClick="uxCancel_Click" CausesValidation="False" /></p>
<div style="margin-top: 20px;">
<asp:Literal ID="uxFailureText" runat="server"
EnableViewState="False"></asp:Literal>
</div>
对于背后的代码,至少需要这么多代码:
MembershipUser user = Membership.GetUser(GuidUserID);
string password = uxPassword.Text;
string newquestion = uxNewQuestion.Text;
string newanswer = uxNewAnswer.Text;
if (user.ChangePasswordQuestionAndAnswer(password, newquestion, newanswer))
{
Response.Redirect("~/Admin/Default.aspx", true);
}
else
{
uxFailureText.Text = string.Format("<p class='error'>There has been a
problem updating your security question.</p>");
}
如果您注意到控件的介绍文本说我们需要密码来确认更改。这是正确的,因为成员资格提供程序方法需要传递当前密码以及旧的和新的安全问题。大多数密码是单向加密的,因此我将此控件作为自助服务类型提供给用户,而不是在管理方面。
祝你好运,并希望这有助于一些人。