public static SessionManager.SessionExt SessionExt(this Controller controller) { var session = CallContext.GetData("session") as SessionManager.SessionExt; if (session == null) { session = new SessionManager.SessionExt(controller.HttpContext); CallContext.SetData("session", session); } return(session); }
/// <summary> /// /// </summary> /// <param name="user"></param> public static void AddLoginLog(SysUser user) { var session = new SessionManager.SessionExt(HttpContext.Current); var log = new SysLoginLog(); log.LoginTime = DateTime.Now; log.LogoutTime = DateTime.Now.AddMinutes(2); //log.OtherInfo = GetRequestParams(HttpContext.Current.Request); log.TenantId = user.TenantId; log.UserId = user.UserId; log.ClientIp = WebClient.GetClientIp(); _dataAccess.AddEntity(log); session["login-logId"] = log.LogId; }
/// <summary> /// 刷新在线时间 /// </summary> public static void SetAlive() { var session = new SessionManager.SessionExt(HttpContext.Current); if (!session.Exists("login-logId")) { return; } lock (lkhelp) { var exec = false;//是否需要执行数据库更新操作 var logId = (int)session["login-logId"]; if (lastUpDateTimes.ContainsKey(logId)) { var lastTime = lastUpDateTimes[logId]; if ((DateTime.Now - lastTime).TotalMinutes >= 1) { exec = true; lastUpDateTimes[logId] = DateTime.Now; } } else { lastUpDateTimes.Add(logId, DateTime.Now); exec = true; } if (exec) { SysLoginLog log = _dataAccess.Get <SysLoginLog>(logId); if (log == null) { return; } log.LogoutTime = DateTime.Now; _dataAccess.UpdateField("Sys_LoginLog", "LogoutTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Sys_LoginLog.LogId=" + logId); } } }