界面登录问题
发表在ASP.NET图书答疑
2015-04-18
是否精华
是
否
版块置顶:
是
否
第23章登录界面代码如何改写可分别登录到管理员界面和用户界面
protected void btnLogin_Click(object sender, EventArgs e)
{
//实例化公共类对象
DB db = new DB();
string userName = this.txtUserName.Text.Trim();
string passWord = db.GetMD5(this.txtPwd.Text.Trim());//对密码进行加密处理
string num = this.txtValidateNum.Text.Trim();
if (Session["ValidateNum"].ToString() == num.ToUpper())
{
//获取用户信息
SqlDataReader dr = db.reDr("select * from tb_User where UserName='" + userName + "' and PassWord='" + passWord + "'");
dr.Read();
if (dr.HasRows)//通过dr中是否包含行判断用户是否通过身份验证
{
Session["UserID"] = dr.GetValue(0);//将该用户的ID存入Session["UserID"]中
Session["Role"] = dr.GetValue(4);//将该用户的权限存入Session["Role"]中
Response.Redirect("~/UserManagement.aspx");//跳转到主页
}
else
{
Response.Write("<script>alert('登录失败!请返回查找原因');location='Login.aspx'</script>");
}
dr.Close();
}
else
{
Response.Write("<script>alert('验证码输入错误!');location='Login.aspx'</script>");
}
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
//实例化公共类对象
DB db = new DB();
string userName = this.txtUserName.Text.Trim();
string passWord = db.GetMD5(this.txtPwd.Text.Trim());//对密码进行加密处理
string num = this.txtValidateNum.Text.Trim();
if (Session["ValidateNum"].ToString() == num.ToUpper())
{
//获取用户信息
SqlDataReader dr = db.reDr("select * from tb_User where UserName='" + userName + "' and PassWord='" + passWord + "'");
dr.Read();
if (dr.HasRows)//通过dr中是否包含行判断用户是否通过身份验证
{
Session["UserID"] = dr.GetValue(0);//将该用户的ID存入Session["UserID"]中
Session["Role"] = dr.GetValue(4);//将该用户的权限存入Session["Role"]中
Response.Redirect("~/UserManagement.aspx");//跳转到主页
}
else
{
Response.Write("<script>alert('登录失败!请返回查找原因');location='Login.aspx'</script>");
}
dr.Close();
}
else
{
Response.Write("<script>alert('验证码输入错误!');location='Login.aspx'</script>");
}
}
}