ASP.NET Tutorial/Authentication Authorization/providers
Содержание
Configuring Create User Form Fields
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.
Requiring a Security Question and Answer
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>
Sending the Original Password
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>
Using Templates with the PasswordRecovery Control
<%@ 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">
<div>
<asp:PasswordRecovery
id="PasswordRecovery1"
Runat="server">
<MailDefinition
From="Admin@YourSite.ru"
Subject="Password Reminder"
BodyFileName="PasswordRecovery.txt" />
<UserNameTemplate>
<h1>User Name</h1>
<asp:Label
id="FailureText"
EnableViewState="false"
ForeColor="Red"
Runat="server" />
<br />
<asp:Label
id="lblUserName"
Text="Enter your user name:"
AssociatedControlID="UserName"
Runat="server" />
<br />
<asp:TextBox
id="UserName"
Runat="server" />
<br />
<asp:Button
id="btnSubmit"
Text="Next"
CommandName="Submit"
Runat="server" />
</UserNameTemplate>
<QuestionTemplate>
<h1>Security Question</h1>
<asp:Label
id="FailureText"
EnableViewState="false"
ForeColor="Red"
Runat="server" />
<br />
<asp:Label
id="Question"
Text="Enter your user name:"
AssociatedControlID="Answer"
Runat="server" />
<br />
<asp:TextBox
id="Answer"
Runat="server" />
<br />
<asp:Button
id="btnSubmit"
Text="Next"
CommandName="Submit"
Runat="server" />
</QuestionTemplate>
<SuccessTemplate>
<h1>Success</h1>
An email has been sent to your registered
email account that contains your user name
and password.
</SuccessTemplate>
</asp:PasswordRecovery>
</div>
</form>
</body>
</html>
File: PasswordRecovery.txt
Here"s your login information:
user name: <%UserName%>
password: <%Password%>