public AjaxMessage SaveLoginCookie(string loginName, string passWord, bool state) { AjaxMessage ajax = new AjaxMessage(); ajax.IsSuccess = false; ajax.Message = ""; try { if (state) { ajax.IsSuccess = true; StringControl.DeleteCookie("Employee"); HttpCookie cookie = new HttpCookie("Employee"); cookie.Values.Add("Name", loginName); cookie.Values.Add("Pwd", passWord); cookie.Values.Add("State", state.ToString()); cookie.Expires = System.DateTime.Now.AddDays(7); HttpContext.Current.Response.Cookies.Add(cookie); } else { StringControl.DeleteCookie("Employee"); ajax.IsSuccess = true; } } catch (Exception e) { ajax.Message = e.Message; } return(ajax); }
/// <summary> /// 注销当前帐号 /// </summary> public void singOut() { //清除全部Session Session.Abandon(); StringControl.DeleteCookie("Login"); //注销 FormsAuthentication.SignOut(); Response.Write("<script>this.top.window.location.href ='/AdminWorkArea/Login.aspx'</script>"); }
/// <summary> /// 登录 /// </summary> protected void btnLogin_Click(object sender, EventArgs e) { string loginName = Request["loginName"].ToString().Trim(); string passwords = Request["passWord"].ToString().Trim(); bool IsCheck = ChkLoginState.Checked; Sys_Employee m_emp = _empService.GetByLoginName(loginName); if (m_emp != null) { if (m_emp.PassWord != passwords.MD5Hash()) { JavaScriptTools.AlertWindow("密码输入错误", Page); return; } } else { JavaScriptTools.AlertWindow("帐号不存在", Page); return; } #region 利用方法 获取帐号 密码 var form = System.Web.HttpContext.Current.Request.Form; string name = CommonTools.GetKeyValue(form, "loginName"); string password = CommonTools.GetKeyValue(form, "passWord"); #endregion //保存个人登录信息 FormsAuthentication.RedirectFromLoginPage(m_emp.EmployeeID.ToString(), false); //写入登录日志 LoginLog(m_emp); //保存Session UserEmployee user = new UserEmployee(); user.EmployeeId = m_emp.EmployeeID; user.LoginName = m_emp.LoginName; user.EmployeeName = m_emp.EmployeeName; Session["UserInfo"] = user; //html页面验证Cookie是否已经登录(/Script/PublicCommon.js) StringControl.DeleteCookie("Login"); HttpCookie cookie = new HttpCookie("Login"); cookie.Values.Add("EmpId", user.EmployeeId.ToString()); cookie.Expires = System.DateTime.Now.AddDays(7); HttpContext.Current.Response.Cookies.Add(cookie); WebService.Login login = new WebService.Login(); login.SaveLoginCookie(loginName, passwords, IsCheck); }