wavaya 发表于 2013-1-26 14:10:11

2、使用CreateUserWizard控件

使用CreateUserWizard控件

CreateUserWizard输出一个用户注册表单,那么一个新用户将添加到网站中。在后台,CreateUserWizard控件使用Asp.netMemebership来创建新用户

ShowCreateUserWizard.aspx
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <style type="text/css">      .createUser      {            width: 350px;            font: 14px Verdana,Sans-Serif;            background-color: lightBlue;            border: solid 3px black;            padding: 4px;      }      .createUser_title      {            background-color: darkblue;            color: White;            font-weight: bold;      }      .createUser_instructions      {            font-size: 12px;            text-align: left;            padding: 10px;      }      .createUser_button      {            border: solid 1px black;            padding: 3px;      }    </style>    <title>Show CreateUserWizard</title></head><body>    <form id="form1" runat="server">    <div>      <asp:CreateUserWizard ID="CreateUserWizard1" ContinueDestinationPageUrl="~/Default.aspx"            InstructionText="Please complete the following from to register at this Website."            CompleteSuccessText="Your new account has been created. Thank you for registering."            CssClass="createUser" TitleTextStyle-CssClass="createUser_title" InstructionTextStyle-CssClass="createUser_instructions"            CreateUserButtonStyle-CssClass="createUser_button" ContinueButtonStyle-CssClass="createUser_button"            runat="server" />    </div>    </form></body></html>

1、配置自定义用户表单字段

Web.Config
<?xml version="1.0"?><!--有®D关?如¨?何?配?置? ASP.NET 应®|用®?程¨¬序¨°的Ì?详¨º细?信?息¡é,ê?请?访¤?问¨ºhttp://go.microsoft.com/fwlink/?LinkId=169433--><configuration><connectionStrings>    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/></connectionStrings><system.web>    <compilation debug="true" targetFramework="4.0"/>    <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><system.webServer>    <modules runAllManagedModulesForAllRequests="true"/></system.webServer></configuration>

精简版的
CreateUserWizardShort.aspx
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>CreateUserWizard Short</title></head><body>    <form id="form1" runat="server">    <div>      <asp:CreateUserWizard ID="CreateUserWizard1" RequireEmail="false" runat="server" />    </div>    </form></body></html>

2、发送已创建用户电子邮件通知
注册新用户后自动发送电子邮件通知。
CreateUserWizardEmail.aspx
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>Create Wizard Email</title></head><body>    <form id="form1" runat="server">    <div>      <asp:CreateUserWizard ID="CreateUserWizard1" runat="server">            <MailDefinition BodyFileName="Register.txt" Subject="Registration Confirmation" From="wayhua@126.com" />      </asp:CreateUserWizard>    </div>    </form></body></html>

Register.txt
Thank you for registering!Here is your new username and password;Username:<% UserName %>Password:<% Password %>

Web.Config配置文件
<configuration><connectionStrings>    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/></connectionStrings><system.net>    <mailSettings>      <smtp>      <networkhost="smtp.126.com" userName="wayhua" password="***"/>      </smtp>    </mailSettings></system.net>....

3、用户自动重定向来源页面
当用户通过页面Login.aspx中的表单成功登录后,将会自动重定向回其请求的来源页面。

4、自动生成密码
自动生成密码
CreateUserWizardPasswordConfirmation.aspx
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title></head><body>    <form id="form1" runat="server">    <div>      <asp:CreateUserWizard ID="CreateUserWizard1" CompleteSuccessText="A confirmation email containing your new password has been sent to your email address"            AutoGeneratePassword="true" LoginCreatedUser="false" ContinueDestinationPageUrl="~/LoginReturn.aspx"            runat="server">            <MailDefinition From="wayhua@126.com" BodyFileName="PasswordConfirmation.htm" IsBodyHtml="true"                Subject="Registration confirmation" />      </asp:CreateUserWizard>    </div>    </form></body></html>

PasswordConfirmation.htm
<!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>    <title>Password Confirmation</title></head><body>    Your new password is    <% Password %></body></html>

用户自己选择密码,确认前不可用。发送邮件确认后方可用

5、在CreateUserWizard控件中使用模板
6、在CreateUserWizard控件中添加注册步骤
P36-P40
2011-5-314:32:08 danny
页: [1]
查看完整版本: 2、使用CreateUserWizard控件