用户登录信息检测
View Code
////存储用户登录信息 private UserInfo _GustUserDynamicInfor; public UserInfo GustUserDynamicInfor { get { if (_GustUserDynamicInfor == null) { if (Session["GuestUser"] != null) { //判断当前session与Cookies中的UserID是否一致,如果不一致,按照Cookies中的User_ID重新赋价值 if (HttpContext.Current.Request.Cookies["GuestUserID"] != null) { if (HttpContext.Current.Request.Cookies["GuestUserID"].Value.Trim().Length > 0) { //不一致 if ((Session["GuestUser"] as UserInfo).User_ID.ToString() != HttpContext.Current.Request.Cookies["GuestUserID"].Value.Trim()) { _GustUserDynamicInfor = (new User()).GetUserInfoByUser_ID(Convert.ToInt32(HttpContext.Current.Request.Cookies["GuestUserID"].Value)); Session["GuestUser"] = _GustUserDynamicInfor; } } } if (_GustUserDynamicInfor == null) { _GustUserDynamicInfor = Session["GuestUser"] as UserInfo; } } else { //Session["PortalUser"] = (new Com.Netmarch.BLL.User()).GetUserInfoByUser_Accounts("Michael1"); //_portalDynamicInfor = Session["PortalUser"] as UserInfo; if (HttpContext.Current.Request.Cookies["GuestUserID"] != null) { try { //在多浏览器测试时Convert.ToInt32(HttpContext.Current.Request.Cookies["GuestUserID"].Value)会报错 _GustUserDynamicInfor = (new User()).GetUserInfoByUser_ID(Convert.ToInt32(HttpContext.Current.Request.Cookies["GuestUserID"].Value)); } catch { //过期该cookies DateTime dtExpires = DateTime.Now.AddHours(-1); Response.Cookies["GuestUserID"].Expires = dtExpires; _GustUserDynamicInfor = null; } } //else //{ // Response.Redirect("/Default.aspx"); //} } } return _GustUserDynamicInfor; } set { _GustUserDynamicInfor = value; } }
道之所在,虽千万人吾往矣