membership
webconfig设置
<?xml version="1.0"?>
<!-- 注意: 除了手动编辑此文件以外,您还可以使用 Web 管理工具来
配置应用程序的设置。可以使用 Visual Studio 中的“网站”->“ASP.NET 配置”
选项。
设置和注释的完整列表在
machine.config.comments 中,该文件通常位于 \Windows\Microsoft.NET\Framework\v2.0.xxxxx\Config 中
-->
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
</appSettings>
<connectionStrings>
<add name="cm" connectionString="Data Source=127.0.0.1;Initial Catalog=NewHelloWord;User ID=苍冥;Password=苍冥"/>
</connectionStrings>
<system.web>
<!-- 用户表 -->
<membership defaultProvider="HelloWord" userIsOnlineTimeWindow="30">
<providers>
<clear/>
<add name="HelloWord" type="System.Web.Security.SqlMembershipProvider" connectionStringName="cm" applicationName="HelloWord" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" requiresUniqueEmail="true" passwordFormat="Hashed"/>
</providers>
</membership>
<!-- 用户表扩展 -->
<!--<profile enabled="true" defaultProvider="HelloWord">
<providers>
<add
name="HelloWord"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="cm" applicationName="HelloWord" />
</providers>
<properties>
<group name="Userinfo">
<add name="Time" type="DateTime" />
</group>
</properties>
</profile>-->
<!--
设置 compilation debug="true" 将调试符号插入已编译的页面中。
但由于这会影响性能,因此只在开发过程中将此值设置为 true。
-->
<compilation debug="true"/>
<!--
通过 <authentication> 节可以配置 ASP.NET 使用的
安全身份验证模式,以标识传入的用户。
-->
<authentication mode="Forms">
<forms name="system" loginUrl="Login.aspx" protection="All" domain="******" timeout="30">
</forms>
</authentication>
<!--
如果在执行请求的过程中出现未处理的错误,则通过 <customErrors> 节
可以配置相应的处理步骤。具体说来,开发人员通过该节可以
配置要显示的 html 错误页以代替错误堆栈跟踪。
-->
<customErrors defaultRedirect="~/error403.aspx"/>
<!--
完全限定客户端重定向的 URL
有些移动设备要求对客户端重定向的 URL 进行完全限定。
-->
<httpRuntime useFullyQualifiedRedirectUrl="true"/>
<!--
指定无 Cookie 的数据字典类型
这将使字典内容出现在本地请求 url 查询字符串中。
这是在无 Cookie 的设备上进行 Forms 身份验证所必需的。
-->
<mobileControls cookielessDataDictionaryType="System.Web.Mobile.CookielessData"/>
<deviceFilters>
<filter name="isJPhone" compare="Type" argument="J-Phone"/>
<filter name="isHTML32" compare="PreferredRenderingType" argument="html32"/>
<filter name="isWML11" compare="PreferredRenderingType" argument="wml11"/>
<filter name="isCHTML10" compare="PreferredRenderingType" argument="chtml10"/>
<filter name="isGoAmerica" compare="Browser" argument="Go.Web"/>
<filter name="isMME" compare="Browser" argument="Microsoft Mobile Explorer"/>
<filter name="isMyPalm" compare="Browser" argument="MyPalm"/>
<filter name="isPocketIE" compare="Browser" argument="Pocket IE"/>
<filter name="isUP3x" compare="Type" argument="Phone.com 3.x Browser"/>
<filter name="isUP4x" compare="Type" argument="Phone.com 4.x Browser"/>
<filter name="isEricssonR380" compare="Type" argument="Ericsson R380"/>
<filter name="isNokia7110" compare="Type" argument="Nokia 7110"/>
<filter name="prefersGIF" compare="PreferredImageMIME" argument="image/gif"/>
<filter name="prefersWBMP" compare="PreferredImageMIME" argument="image/vnd.wap.wbmp"/>
<filter name="supportsColor" compare="IsColor" argument="true"/>
<filter name="supportsCookies" compare="Cookies" argument="true"/>
<filter name="supportsJavaScript" compare="Javascript" argument="true"/>
<filter name="supportsVoiceCalls" compare="CanInitiateVoiceCall" argument="true"/>
</deviceFilters>
<globalization requestEncoding="utf-8" responseEncoding="utf-8"
fileEncoding="utf-8" />
</system.web>
<!--仿问管理-->
<location path="login/userinfo.aspx">
<system.web>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="ChangePassword.aspx">
<system.web>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</location>
<!--仿问管理-->
<!---邮件设制-->
<system.net>
<mailSettings>
<smtp from="biscolussi@sina.com">
<network host="SMTP.sina.com.cn" password="******" userName="biscolussi@sina.com"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
注册
1
protected void Button_reg_Click(object sender, EventArgs e)
2
{
3
if (TextBox_password_1.Text != TextBox_password_2.Text)
4
{
5
Label_error.Text = "错误提示:"+"密码不相同,请重新输入";
6
TextBox_password_1.Text = "";
7
TextBox_password_2.Text = "";
8
}
9
else
10
{
11
MembershipCreateStatus errorText = new MembershipCreateStatus();
12
Membership.CreateUser(TextBox_username.Text, TextBox_password_1.Text, TextBox_Email.Text, DropDownList_Question.Text, TextBox_Answer.Text, true, out errorText);
13
14
switch (errorText)
15
{
16
case MembershipCreateStatus.Success:
17
FormsAuthentication.SetAuthCookie(TextBox_username.Text, false);
18
TextBox_username.Text = "";
19
TextBox_password_1.Text = "";
20
TextBox_password_2.Text = "";
21
TextBox_Email.Text = "";
22
TextBox_Answer.Text = "";
23
Response.Redirect("vlike_reg_3.aspx");
24
break;
25
case MembershipCreateStatus.InvalidUserName:
26
Label_error.Text = "错误提示:" + "用户名不符合要求请重新输入";
27
TextBox_username.Text = "";
28
break;
29
case MembershipCreateStatus.InvalidEmail:
30
Label_error.Text = "错误提示:" + "此邮箱格式错误,请输入正确的邮箱";
31
TextBox_Email.Text = "";
32
break;
33
case MembershipCreateStatus.InvalidPassword:
34
Label_error.Text = "错误提示:" + "弱密码,请重新输入";
35
TextBox_password_1.Text = "";
36
TextBox_password_2.Text = "";
37
break;
38
case MembershipCreateStatus.InvalidQuestion:
39
Label_error.Text = "错误提示:" + "密码提示问题格式错误";
40
break;
41
case MembershipCreateStatus.InvalidAnswer:
42
Label_error.Text = "错误提示:" + "密码提示答案格式错误";
43
TextBox_Answer.Text = "";
44
break;
45
case MembershipCreateStatus.DuplicateUserName:
46
Label_error.Text = "错误提示:" + "此用户已存在,请输入其它用户名";
47
TextBox_username.Text = "";
48
break;
49
case MembershipCreateStatus.DuplicateEmail:
50
Label_error.Text = "错误提示:" + "此邮箱已注册过,请换个邮箱进行注册";
51
TextBox_Email.Text = "";
52
break;
53
}
54
}
55
}
protected void Button_reg_Click(object sender, EventArgs e)2
{3
if (TextBox_password_1.Text != TextBox_password_2.Text)4
{5
Label_error.Text = "错误提示:"+"密码不相同,请重新输入";6
TextBox_password_1.Text = "";7
TextBox_password_2.Text = "";8
}9
else10
{11
MembershipCreateStatus errorText = new MembershipCreateStatus();12
Membership.CreateUser(TextBox_username.Text, TextBox_password_1.Text, TextBox_Email.Text, DropDownList_Question.Text, TextBox_Answer.Text, true, out errorText);13

14
switch (errorText)15
{16
case MembershipCreateStatus.Success:17
FormsAuthentication.SetAuthCookie(TextBox_username.Text, false);18
TextBox_username.Text = "";19
TextBox_password_1.Text = "";20
TextBox_password_2.Text = "";21
TextBox_Email.Text = "";22
TextBox_Answer.Text = "";23
Response.Redirect("vlike_reg_3.aspx");24
break;25
case MembershipCreateStatus.InvalidUserName:26
Label_error.Text = "错误提示:" + "用户名不符合要求请重新输入";27
TextBox_username.Text = "";28
break;29
case MembershipCreateStatus.InvalidEmail:30
Label_error.Text = "错误提示:" + "此邮箱格式错误,请输入正确的邮箱";31
TextBox_Email.Text = "";32
break;33
case MembershipCreateStatus.InvalidPassword:34
Label_error.Text = "错误提示:" + "弱密码,请重新输入";35
TextBox_password_1.Text = "";36
TextBox_password_2.Text = "";37
break;38
case MembershipCreateStatus.InvalidQuestion:39
Label_error.Text = "错误提示:" + "密码提示问题格式错误";40
break;41
case MembershipCreateStatus.InvalidAnswer:42
Label_error.Text = "错误提示:" + "密码提示答案格式错误";43
TextBox_Answer.Text = "";44
break;45
case MembershipCreateStatus.DuplicateUserName:46
Label_error.Text = "错误提示:" + "此用户已存在,请输入其它用户名";47
TextBox_username.Text = "";48
break;49
case MembershipCreateStatus.DuplicateEmail:50
Label_error.Text = "错误提示:" + "此邮箱已注册过,请换个邮箱进行注册";51
TextBox_Email.Text = "";52
break;53
}54
}55
}登陆
1
FormsAuthentication.SetAuthCookie(TextBox_username.Text, false);
2
Response.Redirect("userinfo.aspx");
FormsAuthentication.SetAuthCookie(TextBox_username.Text, false);2
Response.Redirect("userinfo.aspx");退出
1
FormsAuthentication.SignOut();
2
Response.Redirect("login.aspx");
FormsAuthentication.SignOut();2
Response.Redirect("login.aspx");找回密码
在WEB.CONFIG里已设置了邮件设置这里只需拖入一个PasswordRecovery控件就行,修改一下样式风格,配置一下邮箱发送失败的错误页及成功页.还有就是邮件的发送内容配一下就行
更改密码
拖入Changepassword控件,做下美工就OK了
用户锁定解锁
1
//判断用户是否锁定
2
Membership.getUser(用户名).IsLockedOut();
3
//根据用户名解锁
4
Membership.GetUser(用户名).UnlockUser();
//判断用户是否锁定2
Membership.getUser(用户名).IsLockedOut();3
//根据用户名解锁4
Membership.GetUser(用户名).UnlockUser();删除用户
1
Membership.DeleteUser(用户名);
Membership.DeleteUser(用户名);

浙公网安备 33010602011771号