Ngôn ngữ ASP.NET - PasswordRecovery

Đối tượng điều khiển PasswordRecovery 

Điều khiển PasswordRecovery sử dụng tìm lại mật khẩu hoặc đặt lại mật khẩu. Mật khẩu người sử dụng sẽ được gởi thông qua email lúc đăng ký. 

PasswordRecovery chỉ tìm lại mật khẩu hoặc đặt lại mật khẩu thông qua dịch vụ Membership.

Điều khiển PasswordRecovery  có 3 chế độ xem (views):

  1. Question: Chế độ này người sử dụng nhập câu trả lời cho câu hỏi bảo mật
  2. UserName: Chế độ này người sử dụng nhập email để tìm lại mật khẩu
  3. Success: Chế độ này người sử dụng thông báo cho người dùng

Một số sự kiện thường dùng:

Sự kiện Ý nghĩa
SendingMail Sự kiện này xảy ra khi Server gởi mật khẩu cho người sử dụng, với điều kiện là người sử dụng trả lời đúng cho câu hỏi bảo mật
AnswerLookupError Sự kiện này xảy ra với câu trả lời cho câu hỏi bảo mật bị sai
VerifyingAnswer Sự kiện này xảy ra khi người sử dụng gởi câu trả lời để xác nhận

Một số thuộc tính thường dùng:

Thuộc tính Ý nghĩa
Answer Nhập câu trả lời để người sử dụng xác nhận
FailureTextStyle Định dạng cho nội dung thông báo lỗi
HelpPageIconUrl Liên kết dạng hình đến trang nhận mật khẩu

Ví dụ : Tạo trang web PasswordRecovery .apsx, có điều khiển PasswordRecovery :

Bước 1: Kéo thả điều khiển PasswordRecovery từ ToolBox vào giao diện thiết kế

Bước 2: Định dạng giao diện chọn Auto Format --> Chọn scheme --> Chọn Ok

Bước 3: Nhập lại nội dung chọn Convert To Template (có thể nhập trong properties window)


Code trang PasswordRecovery.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PasswordRecovery.aspx.cs" Inherits="logincontrol_PasswordRecovery" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            width: 307px;
        }
        .auto-style3 {
            width: 150px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:PasswordRecovery ID="PasswordRecovery1" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" Width="340px">
            <SubmitButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775" />
            <InstructionTextStyle Font-Italic="True" ForeColor="Black" />
            <SuccessTextStyle Font-Bold="True" ForeColor="#5D7B9D" />
            <TextBoxStyle Font-Size="0.8em" />
            <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.9em" ForeColor="White" />
            <UserNameTemplate>
                <table cellpadding="4" cellspacing="0" style="border-collapse:collapse;width:100%">
                    <tr>
                        <td class="auto-style1">
                            <table cellpadding="0">
                                <tr>
                                    <td align="center" colspan="2" style="color:White;background-color:#5D7B9D;font-size:0.9em;font-weight:bold;">Tìm mật khẩu?</td>
                                </tr>
                                <tr>
                                    <td align="center" colspan="2" style="color:Black;font-style:italic;">Nhập Username để nhận lại mật khẩu.</td>
                                </tr>
                                <tr>
                                    <td align="right" class="auto-style3">
                                        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
                                    </td>
                                    <td class="auto-style2">
                                        <asp:TextBox ID="UserName" runat="server" Font-Size="0.8em" style="margin-left: 11px" Width="152px"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="PasswordRecovery1">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="center" colspan="2" style="color:Red;">
                                        <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" colspan="2">
                                        <asp:Button ID="SubmitButton" runat="server" BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" CommandName="Submit" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775" Text="Submit" ValidationGroup="PasswordRecovery1" />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </UserNameTemplate>
        </asp:PasswordRecovery>
    
    </div>
    </form>
</body>
</html>

Thực thi trang web cho kết quả: