管理员修改用户
如果是管理员不能被禁止登陆。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace RegeditOfAdoDotnet
{
public partial class AdminModifyUser : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Buffer = true;
Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
Response.Expires = 0;
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "No-Cache");
if (!IsPostBack)
{
string userName = Request.QueryString["user"].ToString();
lblUserName.Text = userName;
MembershipUser user = Membership.GetUser(lblUserName.Text);//获取当前用户
if (user.IsApproved)
{
ckbLicense.Checked = true;
}
else
{
ckbLicense.Checked = false;
}
}
}
/// <summary>
/// 确定
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnConfirm_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
try
{
MembershipUser user = Membership.GetUser(lblUserName.Text);//获取当前用户
string oldPassWord = user.GetPassword();//获取当前用户密码
if (!string.IsNullOrEmpty(txtPassWord.Text.ToString()))
{
string newPassWord = txtPassWord.Text.ToString();//获取新密码
user.ChangePassword(oldPassWord, newPassWord);//修改密码
}
if (!string.IsNullOrEmpty(txtEmail.Text.ToString()))
{
user.Email = txtEmail.Text.ToString();//获取新邮箱
}
//判断用户是否是Admin
if (Roles.IsUserInRole(lblUserName.Text, "Admin"))
{
ckbLicense.Checked = true;
ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>alert('" + lblUserName.Text.ToString() + "是管理员,不能被禁止登陆!');</script>");
}
else
{
if (!ckbLicense.Checked)
{
user.IsApproved = false;
}
else
{
user.IsApproved = true;
}
}
Membership.UpdateUser(user);//更新当前用户注册信息
}
catch (Exception exp)
{
Response.Write(exp.Message); //输出错误信息
}
finally
{
ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>alert('修改成功!');</script>");
}
}
}
/// <summary>
/// 返回
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnBack_Click(object sender, EventArgs e)
{
Response.Redirect("~/Admin/AdminInfo.aspx");
}
/// <summary>
/// 添加用户
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAddUser_Click(object sender, EventArgs e)
{
Response.Redirect("~/Admin/AdminAddUser.aspx");
}
/// <summary>
/// 退出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnExit_Click(object sender, EventArgs e)
{
Session.Clear();
FormsAuthentication.SignOut();
Response.Redirect("~/Goodby.aspx");
}
}
}