yl
2022-07-16 4545b915123fb7b7535b697f6e82b12f525f8b71
VueWebApi/Tools/ChannelActionFilterAttribute.cs
@@ -26,7 +26,10 @@
        /// <param name="actionContext"></param>
        public override void  OnActionExecuting(HttpActionContext actionContext)
        {
            User loginUser = JsonConvert.DeserializeObject<User>(HttpContext.Current.Session["User"].ToString());
            try
            {
                var User = HttpContext.Current.Session["User"].ToString();
                User loginUser = JsonConvert.DeserializeObject<User>(User);
            base.OnActionExecuting(actionContext);
            //如果存在
            if (redis.Get<User>("LoginUserID" + loginUser.userid, 0).userid.ToString() != "")
@@ -42,16 +45,24 @@
                else
                {
                    mes.code = "300";
                    mes.Message = "账户已过期,请重新登录2!";
                        mes.Message = "登录已超时,请重新登录!";
                    actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.Ambiguous, Content = new StringContent(JsonConvert.SerializeObject(mes), Encoding.GetEncoding("UTF-8"), "application/json") };
                }
            }
            else //如果redis登录用户中不存在当前用户
            {
                mes.code = "300";
                mes.Message = "账户已过期,请重新登录1!";
                    mes.Message = "登录已超时,请重新登录!";
                actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.Ambiguous, Content = new StringContent(JsonConvert.SerializeObject(mes), Encoding.GetEncoding("UTF-8"), "application/json") };
            }
        }  
            catch (Exception)
            {
                mes.code = "300";
                mes.Message = "登录已超时,请重新登录!";
                actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.Ambiguous, Content = new StringContent(JsonConvert.SerializeObject(mes), Encoding.GetEncoding("UTF-8"), "application/json") };
            }
        }
    }
}