| | |
| | | /// <param name="actionContext"></param> |
| | | public override void OnActionExecuting(HttpActionContext actionContext) |
| | | { |
| | | User loginUser = JsonConvert.DeserializeObject<User>(HttpContext.Current.Session["User"].ToString()); |
| | | base.OnActionExecuting(actionContext); |
| | | //如果存在 |
| | | if (redis.Get<User>("LoginUserID" + loginUser.userid, 0).userid.ToString() != "") |
| | | try |
| | | { |
| | | //获取redis中当前用户信息 |
| | | User r_loginUser = redis.Get<User>("LoginUserID" + loginUser.userid, 0); |
| | | //如果session中的用户guid和redis中的用户guid匹配 |
| | | if (r_loginUser.guid.Equals(loginUser.guid)) |
| | | var rediskey = HttpContext.Current.Request.Cookies["rediskey"].Value.ToString(); |
| | | base.OnActionExecuting(actionContext); |
| | | //如果存在 |
| | | if (redis.Get<User>(rediskey, 0).userid.ToString() != "") |
| | | { |
| | | //重置过期时间 |
| | | redis.Set<User>("LoginUserID" + loginUser.userid, loginUser, redis.secondsTimeOut, 0); |
| | | //获取redis中当前用户信息 |
| | | User r_loginUser = redis.Get<User>(rediskey, 0); |
| | | //如果session中的用户guid和redis中的用户guid匹配 |
| | | if (r_loginUser.rediskey.Equals(rediskey)) |
| | | { |
| | | //重置过期时间 |
| | | redis.KeyExpire(rediskey, redis.secondsTimeOut); |
| | | } |
| | | else |
| | | { |
| | | mes.code = "303"; |
| | | mes.Message = "登录已超时,请重新登录!"; |
| | | actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(mes), Encoding.GetEncoding("UTF-8"), "application/json") }; |
| | | } |
| | | } |
| | | else |
| | | else //如果redis登录用户中不存在当前用户 |
| | | { |
| | | mes.code = "300"; |
| | | mes.Message = "账户已过期,请重新登录2!"; |
| | | actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.Ambiguous, Content = new StringContent(JsonConvert.SerializeObject(mes), Encoding.GetEncoding("UTF-8"), "application/json") }; |
| | | mes.code = "303"; |
| | | mes.Message = "登录已超时,请重新登录!"; |
| | | actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(mes), Encoding.GetEncoding("UTF-8"), "application/json") }; |
| | | } |
| | | } |
| | | else //如果redis登录用户中不存在当前用户 |
| | | catch (Exception) |
| | | { |
| | | mes.code = "300"; |
| | | mes.Message = "账户已过期,请重新登录1!"; |
| | | actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.Ambiguous, Content = new StringContent(JsonConvert.SerializeObject(mes), Encoding.GetEncoding("UTF-8"), "application/json") }; |
| | | mes.code = "303"; |
| | | mes.Message = "登录已超时,请重新登录!"; |
| | | actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(mes), Encoding.GetEncoding("UTF-8"), "application/json") }; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |