创建用户:
MembershipCreateStatus mc;
Membership.CreateUser(txtUid.Text, txtPwd.Text, txtEmail.Text, txtQuestion.Text, txtAnswer.Text, true, out mc);
Response.Write(mc.ToString());
删除用户:
if (Membership.DeleteUser(txtUid.Text))//获取用户key主键Membership.DeleteUser(key)
Response.Write("OK");
else
Response.Write("Error");
修改用户信息:
if (User.Identity.IsAuthenticated)
{
MembershipUser user = Membership.GetUser();
user.Email = txtEmail.Text;
Membership.UpdateUser(user);
Response.Write(user.Email.ToString());
}
验证用户登录信息
bool isok = Membership.ValidateUser(txtUid.Text, txtPwd.Text);
if (isok)
{
FormsAuthentication.SetAuthCookie(txtUid.Text, false);
Response.Write("OK");
}
else
{
Response.Write("Error");
}
获取登录用户的信息
if (User.Identity.IsAuthenticated)
{
MembershipUser myuser = Membership.GetUser();
if (myuser != null)
{
Response.Write(myuser.CreationDate);
Response.Write(myuser.Email);
Response.Write(myuser.IsLockedOut);
Response.Write(myuser.IsOnline);
Response.Write(myuser.PasswordQuestion);
Response.Write(myuser.UserName);
}
}
根据密码问题的答案返回用户密码
if (User.Identity.IsAuthenticated)
{
MembershipUser user = Membership.GetUser(txtUid.Text);
txtPwd.Text = user.GetPassword(txtAnswer.Text);
}
修改用户密码
if (User.Identity.IsAuthenticated)
{
MembershipUser user = Membership.GetUser();
user.ChangePassword(txtPwd.Text,txtPWd2.Text);
Response.Write(user.GetPassword(txtAnswer.Text));
}
解锁用户
MembershipUser user = Membership.GetUser(txtUid.Text);
bool b = user.UnlockUser();
Response.Write(b+" "+user.IsLockedOut);
拒绝用户登录
MembershipUser user = Membership.GetUser(txtUid.Text);
user.IsApproved = false;
Membership.UpdateUser(user);
Response.Write(user.IsLockedOut);
允许用户登录
MembershipUser user = Membership.GetUser(txtUid.Text);
user.IsApproved = true;
Membership.UpdateUser(user);
Response.Write(user.IsLockedOut);
根据用户名或邮箱来检索用户
MembershipUserCollection users;
switch(listType.Text)
{
case "姓名":
users = Membership.FindUsersByName(txtFind.Text);
if (users.Count > 0)
{
showUserInfo(users);
}
else
{
Response.Write("未找到用户名");
}
break;
case "邮箱":
users = Membership.FindUsersByEmail(txtFind.Text);
if (users.Count > 0)
{
showUserInfo(users);
}
else
{
Response.Write("未找到邮箱");
}
break;
}
(车延禄)
收藏于 2007-06-23