Exemplo n.º 1
0
        /// <summary>
        /// 设置登录Cookie
        /// </summary>
        /// <param name="response"></param>
        /// <param name="code"></param>
        /// <param name="pwd"></param>
        public static void SetLoginCookie(HttpResponse response, string code, string pwd)
        {
            UserCookie userCookie = new UserCookie()
            {
                UserCode = code, UserPwd = pwd
            };
            HttpCookie cookie = new HttpCookie("usrCode")
            {
                Expires = DateTime.Now.AddDays(365 * 100), Value = DataBase.SimpleEncrypt(JsonConvert.SerializeObject(userCookie))
            };

            if (response.Cookies["usrCode"] == null)
            {
                response.Cookies.Add(cookie);
            }
            else
            {
                response.Cookies.Set(cookie);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 是否已经登录
 /// </summary>
 /// <param name="session"></param>
 /// <param name="request"></param>
 /// <param name="response"></param>
 /// <returns></returns>
 public static bool IsLogin(HttpSessionState session, HttpRequest request, HttpResponse response)
 {
     //HttpContext.Current
     if (session["empID"] == null || string.IsNullOrEmpty(DataBase.ObjectToString(session["empID"])))
     {
         UserCookie userCookie = GetLoginCookie(request);
         if (userCookie != null)
         {
             EmployeeInfo employee = employeeService.IsEmployeeExist(userCookie.UserCode, userCookie.UserPwd);
             if (employee != null)
             {
                 UsrAuth.SetLogin(session, employee);
                 SetLoginCookie(response, employee.DepName, userCookie.UserPwd);
                 return(true);
             }
         }
         return(false);
     }
     return(true);
 }