2、使用CreateUserWizard控件

使用CreateUserWizard控件

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

ShowCreateUserWizard.aspx
[code]
<%@ 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>
[/code]

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

Web.Config
[code]
<?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>
[/code]

精简版的
CreateUserWizardShort.aspx
[code]
<%@ 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>
[/code]

2、发送已创建用户电子邮件通知
注册新用户后自动发送电子邮件通知。
CreateUserWizardEmail.aspx
[code]
<%@ 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>
[/code]

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

Web.Config配置文件
[code]
<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>
<network host="smtp.126.com" userName="wayhua" password="***"/>
</smtp>
</mailSettings>
</system.net>
....
[/code]

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

4、自动生成密码
自动生成密码
CreateUserWizardPasswordConfirmation.aspx
[code]
<%@ 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>
[/code]

PasswordConfirmation.htm
[code]
<!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>
[/code]

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

5、在CreateUserWizard控件中使用模板
6、在CreateUserWizard控件中添加注册步骤
P36-P40
2011-5-3 14:32:08 danny
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值