";
break;
Case MembershipCreateStatus.DuplicateEmail
lblResults.Text = "电子邮件已经在使用,请输入一个不同是的电子邮件地址”;
break;
Case Else
lblResults.Text = "An error occurred while creating the user."
}
true是否用户一开通就被授权。
Login.apx
<二>登录事件
string userName = txtUserId.Text;
string password = txtPassword.Text;
if (Membership.ValidateUser(userName, password))
{
If ! (Request.QueryString("ReturnUrl") Is nothing) //如果该项有值则切换到转向此页的页面
{
FormsAuthentication.RedirectFromLoginPage(userName, False);转到调用这个页的页
}
else
{
FormsAuthentication.SetAuthCookie(userName, False);不转到其它页
Response.Redirect("~/secured/menu.aspx");转向其它的页面
}
else
{
lblResults.Visible = True;
lblResults.Text = "Unsuccessful login. Please re-enter your information and try again.";
If (Not Membership.GetUser(userName) Is Nothing)如果验证不正确,且又存在该用户
If(Membership.GetUser(userName).IsLockedOut = true)用户是否已锁定(5次)
lblResults.Text = lblResults.Text & " <b>Your account has been locked out.</b>"
End If
End If
End If
<三>用户的注销
FormsAuthentication.SignOut();//注销用户
Roles.DeleteCookie();//清除cookie
FormsAuthentication.RedirectToLoginPage();//注销后转回到登陆页
用户信息的显示
MemberShipUser memUser=MemberShip.GegUser();
<%=Server.HtmleEncode(memUser.UserName)%>//用户名
<%=Server.HtmleEncode(memUser.Email)%>//用户的电子邮件
<%=Server.HtmleEncode(memUser.IsApproved)%>//是否批准和通过
<%=Server.HtmleEncode(memUser.PasswordQuestion)%>//用户的密码问题
<%=Server.HtmleEncode(memUser.IsOnline)%>// 用户是否在线
<%=Server.HtmleEncode(memUser.LastLoginDate.ToString(“F”))%>//最后登录时间
<%=Server.HtmleEncode(memUser.LastActivityDate.ToString(“F”))%>//最后活动时间
<%=Server.HtmleEncode(memUser.LastPasswordChangeDate.ToString(“F”)%>//最后一次更密码时间
<四>删除当前登录的用户信息
if(MemberShip.Deleteuser(User.Identity.Name))
{
FormAuthentication.SignOut();
Roles.DeleteCookie();
&