ASP.NET Tutorial/Authentication Authorization/providers

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

Configuring Create User Form Fields

   <source lang="csharp">

The following web configuration file makes both an email address and security question and answer optional. File: Web.Config <configuration>

 <system.web>
   <authentication mode="Forms" />
   <membership defaultProvider="MyMembership">
     <providers>
       <add
         name="MyMembership"
         type="System.Web.Security.SqlMembershipProvider"
         connectionStringName="LocalSqlServer"
         requiresQuestionAndAnswer="false"
         requiresUniqueEmail="false" />
     </providers>
   </membership>
 </system.web>

</configuration> If you add the web configuration file to your application, then the CreateUserWizard control does not render fields for a security question and answer.</source>


Requiring a Security Question and Answer

   <source lang="csharp">

File: Web.Config <configuration>

 <system.web>
   <authentication mode="Forms" />
   <membership defaultProvider="MyMembership">
     <providers>
       <add
         name="MyMembership"
         type="System.Web.Security.SqlMembershipProvider"
         connectionStringName="LocalSqlServer"
         requiresQuestionAndAnswer="false"
         />
     </providers>
   </membership>
 </system.web>

</configuration></source>


Sending the Original Password

   <source lang="csharp">

File: Web.Config <configuration>

 <system.web>
   <authentication mode="Forms" />
   <membership defaultProvider="MyMembership">
     <providers>
       <add
         name="MyMembership"
         type="System.Web.Security.SqlMembershipProvider"
         connectionStringName="LocalSqlServer"
         passwordFormat="Clear"
         enablePasswordRetrieval="true"
         />
     </providers>
   </membership>
 </system.web>

</configuration></source>


Using Templates with the PasswordRecovery 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"> </head> <body>

   <form id="form1" runat="server">
   <asp:PasswordRecovery
       id="PasswordRecovery1"
       Runat="server">
       <MailDefinition
           From="Admin@YourSite.ru"
           Subject="Password Reminder"
           BodyFileName="PasswordRecovery.txt" />
       <UserNameTemplate>

User Name

       <asp:Label
           id="FailureText"
           EnableViewState="false"
           ForeColor="Red"
           Runat="server" />
       
<asp:Label id="lblUserName" Text="Enter your user name:" AssociatedControlID="UserName" Runat="server" />
<asp:TextBox id="UserName" Runat="server" />
<asp:Button id="btnSubmit" Text="Next" CommandName="Submit" Runat="server" /> </UserNameTemplate> <QuestionTemplate>

Security Question

       <asp:Label
           id="FailureText"
           EnableViewState="false"
           ForeColor="Red"
           Runat="server" />
       
<asp:Label id="Question" Text="Enter your user name:" AssociatedControlID="Answer" Runat="server" />
<asp:TextBox id="Answer" Runat="server" />
<asp:Button id="btnSubmit" Text="Next" CommandName="Submit" Runat="server" /> </QuestionTemplate> <SuccessTemplate>

Success

       An email has been sent to your registered
       email account that contains your user name
       and password.
       </SuccessTemplate>
   </asp:PasswordRecovery>
   </form>

</body> </html> File: PasswordRecovery.txt Here"s your login information:

 user name: <%UserName%>
 password: <%Password%></source>