private void BindUserList() { BLL.Base_User blluser = new BLL.Base_User(); DataTable dt = blluser.GetAllList().Tables[0]; chkUserList.Items.Clear(); foreach (DataRow r in dt.Rows) { chkUserList.Items.Add(new ListItem( r["UserName"].ToString(), r["UserId"].ToString())); } }
protected void BtnLogin_Click(object sender, EventArgs e) { if (checkinput()) { //判断用户是否存在 string u = txtUserName.Text.Trim(); string p = txtPwd.Text.Trim(); p = Smart.Security.MD5.MD5Encrypt(p).ToUpper(); BLL.Base_User user = new BLL.Base_User(); DataSet ds = new DataSet(); ds = user.GetList(string.Format("UserName='******' and Userpwd='{1}'", u, p)); //跳转到主页面 if (ds != null && ds.Tables[0].Rows.Count != 0) { //setSession Session["username"] = u; Session["pwd"] = p; Session["ssid"] = Session.SessionID; Session["uid"] = ds.Tables[0].Rows[0]["UserId"]; Session["roleid"] = ds.Tables[0].Rows[0]["RoleId"]; Response.Cookies.Add(new HttpCookie("username", u)); Response.Cookies.Add(new HttpCookie("pwd", p)); Response.Cookies.Add(new HttpCookie("ssid", Session.SessionID)); Response.Cookies.Add(new HttpCookie("roleid", ds.Tables[0].Rows[0]["RoleId"].ToString())); Response.Cookies.Add(new HttpCookie("uid", ds.Tables[0].Rows[0]["UserId"].ToString())); //跳转 Response.Redirect("Default.aspx", true); } else { lblmsg.Text = "用户名或密码错误"; txtUserName.Text = ""; txtPwd.Text = ""; txtUserName.Focus(); } } }