/// <summary> /// 获取本逻辑类单例 /// </summary> /// <returns></returns> public static PositionBll GetInstence() { if (_PositionBll == null) { _PositionBll = new PositionBll(); } return _PositionBll; }
/// <summary> /// 判断用户是否超时退出(退出情况:1.系统更新,2.用户自动退出) /// </summary> public void IsTimeOut() { if (HttpContext.Current.Session == null || HttpRuntime.Cache["OnlineUsers"] == null || HttpContext.Current.Session[OnlineUsersTable.UserHashKey] == null) { try { //不存在则表示Session失效了,重新从Cookies中加载 var userHashKey = CookieHelper.GetCookieValue(OnlineUsersTable.UserHashKey); var md5 = CookieHelper.GetCookieValue(OnlineUsersTable.Md5); //判断Cookies是否存在,存在则查询在线列表,重新获取用户信息 if (userHashKey.Length > 0 && md5.Length == 32) { //读取当前用户在线实体 var model = GetModelForCache(x => x.UserHashKey == userHashKey); //当前用户存在在线列表中 if (model != null) { //计算用户md5值 var key = GenerateMd5(model); //判断用户的md5值是否正确 if (md5 == key) { //将UserHashKey存储到缓存中 HttpContext.Current.Session[OnlineUsersTable.UserHashKey] = userHashKey; //获取用户权限并存储到用户Session里 PositionBll.GetInstence().SetUserPower(model.Position_Id); //更新用户当前SessionId到在线表中 //UpdateUserOnlineInfo(model.Id + "", OnlineUsersTable.SessionId, HttpContext.Current.Session.SessionID); //当在线列表缓存不存在时,重新加载数据库记录到缓存中 if (HttpRuntime.Cache["OnlineUsers"] == null) { Load(); } //加载用户相关信息完毕,退出超时检查 return; } } } } catch (Exception e) { //出现异常,保存出错日志信息 CommonBll.WriteLog("", e); } //用户不存在,直接退出 FineUI.Alert.Show("当前用户登录已经过时或系统已更新,请重新登录!", "检测通知", MessageBoxIcon.Information, "top.location='Login.aspx'"); //DotNet.Utilities.JsHelper.AlertAndParentUrl("当前用户登录已经过时或系统已更新,请重新登录!", "Login.aspx"); HttpContext.Current.Response.End(); } }
/// <summary> /// 获取用户页面控件(按键)操作权限 /// </summary> /// <returns></returns> public string GetControlPower() { //读取Session中存储的ControlPower值 var controlPower = SessionHelper.GetSession(PositionTable.ControlPower); //如果为null if (controlPower == null) { //获取用户权限并存储到用户Session里 PositionBll.GetInstence().SetUserPower(GetUserOnlineInfo(GetUserHashKey(), OnlineUsersTable.Position_Id) + ""); } controlPower = SessionHelper.GetSession(PositionTable.ControlPower); return(controlPower + ""); }
/// <summary> /// 获取用户页面控件(按键)操作权限 /// </summary> /// <returns></returns> public string GetControlPower() { //读取Session中存储的ControlPower值 var controlPower = HttpContext.Current.Session[PositionTable.ControlPower]; //如果为null if (controlPower == null) { //获取用户权限并存储到用户Session里 PositionBll.GetInstence().SetUserPower(GetUserOnlineInfo(OnlineUsersTable.Position_Id) + ""); } controlPower = HttpContext.Current.Session[PositionTable.ControlPower]; return(controlPower + ""); }
/// <summary> /// 判断用户是否超时退出(退出情况:1.系统更新,2.用户自动退出) /// </summary> public void IsTimeOut() { if (HttpContext.Current.Session == null || HttpContext.Current.Session[OnlineUsersTable.UserHashKey] == null) { try { //不存在则表示Session失效了,重新从Cookies中加载 var userHashKey = CookieHelper.GetCookieValue(OnlineUsersTable.UserHashKey); var md5 = CookieHelper.GetCookieValue(OnlineUsersTable.Md5); //判断Cookies是否存在,存在则查询在线列表,重新获取用户信息 if (userHashKey.Length > 0 && md5.Length == 32) { //读取当前用户在线实体 var model = GetOnlineUsersModel(userHashKey); //当前用户存在在线列表中 if (model != null) { //计算用户md5值 var key = GenerateMd5(model); //判断用户的md5值是否正确 if (md5 == key) { //将UserHashKey存储到缓存中 HttpContext.Current.Session[OnlineUsersTable.UserHashKey] = userHashKey; //获取用户权限并存储到用户Session里 PositionBll.GetInstence().SetUserPower(model.Position_Id); //更新用户当前SessionId到在线表中 //UpdateUserOnlineInfo(model.Id + "", OnlineUsersTable.SessionId, HttpContext.Current.Session.SessionID); return; } //添加用户下线记录 LoginLogBll.GetInstence().Save(model.Id, "用户【{0}】的账号已经在另一处登录,本次登陆下线!在线时间【{1}】"); //清除在线表里与当前用户同名的记录 Delete(null, x => x.Id == model.Id); //清空Session SessionHelper.RemoveSession(OnlineUsersTable.UserHashKey); SessionHelper.RemoveSession(OnlineUsersTable.Md5); SessionHelper.RemoveSession(PositionTable.PagePower); SessionHelper.RemoveSession(PositionTable.ControlPower); //删除Cookies CookieHelper.ClearCookie(OnlineUsersTable.UserHashKey); CookieHelper.ClearCookie(OnlineUsersTable.Md5); } else { //删除数据库记录与IIS缓存 Delete(null, x => x.UserHashKey == userHashKey); //清空Session SessionHelper.RemoveSession(OnlineUsersTable.UserHashKey); SessionHelper.RemoveSession(OnlineUsersTable.Md5); SessionHelper.RemoveSession(PositionTable.PagePower); SessionHelper.RemoveSession(PositionTable.ControlPower); //删除Cookies CookieHelper.ClearCookie(OnlineUsersTable.UserHashKey); CookieHelper.ClearCookie(OnlineUsersTable.Md5); } } } catch (Exception e) { //出现异常,保存出错日志信息 CommonBll.WriteLog("", e); } //用户不存在,直接退出 //FineUI.Alert.Show("当前用户登录已经过时或系统已更新,请重新登录!", "检测通知", MessageBoxIcon.Information, "top.location='Login.aspx'"); //DotNet.Utilities.JsHelper.AlertAndParentUrl("当前用户登录已经过时或系统已更新,请重新登录!", "Login.aspx"); HttpContext.Current.Response.Redirect("/WebManage/Login.aspx"); HttpContext.Current.Response.End(); } }