using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; namespace Basic.Tools { /// /// 检测会员登录状态 /// public class LoginState { /// /// 判断用户是否登录 /// /// /// public static void UserSession() { Basic.Model.user muser = Basic.Tools.LoginState.GetUserInfo(); if (muser == null) { string URL = "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.RawUrl; System.Web.HttpContext.Current.Response.Write(""); } } /// /// 判断管理员是否已经登录(解决Session超时问题) /// public static bool IsUserLogin() { //如果Session为Null if (System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] != null) { return true; } else { //检查Cookies string username = Basic.Tools.Utils.GetCookie("UserName", "str_key"); //解密用户名 string userpwd = Basic.Tools.Utils.GetCookie("UserPwd", "str_key");//解密密码 if (username != "" && userpwd != "") { DAL.user dal = new DAL.user(); Model.user model = dal.GetModel(username, userpwd); if (model != null) { System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] = model; return true; } } } return false; } /// /// 取得管理员信息 /// public static Model.user GetUserInfo() { if (IsUserLogin()) { Basic.DAL.user dal = new DAL.user(); Model.user model = System.Web.HttpContext.Current.Session[Keys.SESSION_USER_INFO] as Model.user; model = dal.GetModel(model.id); if (model != null) { return model; } } return null; } } }