首页 > 代码库 > asp.net Cookie 用户登陆时记住我
asp.net Cookie 用户登陆时记住我
/// <summary> /// 判断Cookie中存储的数据 /// </summary> protected void CheckUserCookie() { //先判断Cookie是否有值 if (Request.Cookies["cp1"] != null && Request.Cookies["cp2"] != null) { //校验数据是否正确. string cookieUserName = Request.Cookies["cp1"].Value; string cookieUserPwd=Request.Cookies["cp2"].Value; BLL.UserManager bll = new BLL.UserManager(); Model.User model=bll.GetModel(cookieUserName);//根据Cookie中存储的用户名找用户 if (model != null) { //判断密码是否正确. //如果注册时,采用相同的加密方式,那么这里再比较时直接比较 if (Enctry(model.LoginPwd) == cookieUserPwd) { Session["UserInfo"] = model; GoPage("登录成功"); } else//表示密码错误,删除Cookie { Response.Cookies["cp1"].Expires = DateTime.Now.AddDays(-1); Response.Cookies["cp2"].Expires = DateTime.Now.AddDays(-1); } } } } /// <summary> /// 校验用户登录信息 /// </summary> protected void CheckUserLogin() { string txtName=Request.Form["txtName"]; string txtPwd=Request.Form["txtPwd"]; BLL.UserManager bll = new BLL.UserManager(); string msg = string.Empty; Model.User model = null; //校验用户名密码 bool b= bll.UserLogin(txtName, txtPwd,out msg,out model); if (b) { Session["UserInfo"] = model; //如果选择了记住我复选框,将用户的信息写到Cookie。 if (!string.IsNullOrEmpty(Request.Form["checkMe"])) { HttpCookie cookie1 = new HttpCookie("cp1", model.LoginId); HttpCookie cookie2 = new HttpCookie("cp2",Enctry(model.LoginPwd)); cookie1.Expires = DateTime.Now.AddDays(3); cookie2.Expires = DateTime.Now.AddDays(3); Response.Cookies.Add(cookie1); Response.Cookies.Add(cookie2); } GoPage(msg); } else { Response.Redirect("/ShowMsg.aspx?msg=" + Server.UrlEncode(msg) + "&txt=" + Server.UrlEncode("登录页") + "&url=/Login.aspx"); } }
asp.net Cookie 用户登陆时记住我
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。