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