ASP.NET Tutorial/Authentication Authorization/ChangePassword

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Sending a Change Password Email

   <source lang="csharp">

<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">

   <title>ChangePassword Email</title>

</head> <body>

   <form id="form1" runat="server">
   <asp:ChangePassword
       id="ChangePassword1"
       DisplayUserName="true"
       Runat="server">
       <MailDefinition
           From="Admin@YourSite.ru"
           BodyFileName="ChangePassword.txt"
           Subject="Your New Password" />
   </asp:ChangePassword>
   </form>

</body> </html> File: ChangePassword.txt <%UserName%>, your new password is <%Password%>.</source>


Using Templates with the ChangePassword Control

   <source lang="csharp">

<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">

   <title>ChangePassword Template</title>

</head> <body>

   <form id="form1" runat="server">
   <asp:ChangePassword
       id="ChangePassword1"
       DisplayUserName="true"
       Runat="server">
       <ChangePasswordTemplate>

Change Password

           <asp:Label
               id="FailureText"
               EnableViewState="false"
               ForeColor="Red"
               Runat="server" />
           
<asp:Label id="lblUserName" Text="User Name:" AssociatedControlID="UserName" Runat="server" />
<asp:TextBox id="UserName" Runat="server" />

<asp:Label id="lblCurrentPassword" Text="Current Password:" AssociatedControlID="CurrentPassword" Runat="server" />
<asp:TextBox id="CurrentPassword" TextMode="Password" Runat="server" />

<asp:Label id="lblNewPassword" Text="New Password:" AssociatedControlID="NewPassword" Runat="server" />
<asp:TextBox id="NewPassword" TextMode="Password" Runat="server" />

<asp:Button id="btnChangePassword" Text="Change Password" CommandName="ChangePassword" Runat="server" /> </ChangePasswordTemplate> <SuccessTemplate> Your password has been changed! </SuccessTemplate> </asp:ChangePassword>
   </form>

</body> </html></source>


Using the ChangePassword Control

   <source lang="csharp">

<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">

   <title>Show ChangePassword</title>

</head> <body>

   <form id="form1" runat="server">
   <asp:LoginName ID="LoginName1" runat="server" />
   <asp:ChangePassword
       id="ChangePassword1"
       InstructionText="Complete this form to create a new password."
       DisplayUserName="true"
       ContinueDestinationPageUrl="~/Default.aspx"
       CancelDestinationPageUrl="~/Default.aspx"
       Runat="server" />
   </form>

</body> </html></source>