From 4545b915123fb7b7535b697f6e82b12f525f8b71 Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期六, 16 七月 2022 21:16:19 +0800
Subject: [PATCH] 工序检验接口编写

---
 VueWebApi/Tools/ChannelActionFilterAttribute.cs |   39 +++++++++++++++++++++++++--------------
 1 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/VueWebApi/Tools/ChannelActionFilterAttribute.cs b/VueWebApi/Tools/ChannelActionFilterAttribute.cs
index f219bd2..fa4b7e5 100644
--- a/VueWebApi/Tools/ChannelActionFilterAttribute.cs
+++ b/VueWebApi/Tools/ChannelActionFilterAttribute.cs
@@ -26,32 +26,43 @@
         /// <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涓殑鐢ㄦ埛usercode鍜宺edis涓殑鐢ㄦ埛usercode鍖归厤
-                if (r_loginUser.usercode.Equals(loginUser.usercode))
+                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() != "")
                 {
-                    //閲嶇疆杩囨湡鏃堕棿
-                    redis.Set<User>("LoginUserID" + loginUser.userid, loginUser, redis.secondsTimeOut, 0);
+                    //鑾峰彇redis涓綋鍓嶇敤鎴蜂俊鎭�
+                    User r_loginUser = redis.Get<User>("LoginUserID" + loginUser.userid, 0);
+                    //濡傛灉session涓殑鐢ㄦ埛usercode鍜宺edis涓殑鐢ㄦ埛usercode鍖归厤
+                    if (r_loginUser.usercode.Equals(loginUser.usercode))
+                    {
+                        //閲嶇疆杩囨湡鏃堕棿
+                        redis.Set<User>("LoginUserID" + loginUser.userid, loginUser, redis.secondsTimeOut, 0);
+                    }
+                    else
+                    {
+                        mes.code = "300";
+                        mes.Message = "鐧诲綍宸茶秴鏃�,璇烽噸鏂扮櫥褰�!";
+                        actionContext.Response = new HttpResponseMessage { StatusCode = HttpStatusCode.Ambiguous, Content = new StringContent(JsonConvert.SerializeObject(mes), Encoding.GetEncoding("UTF-8"), "application/json") };
+                    }
                 }
-                else
+                else //濡傛灉redis鐧诲綍鐢ㄦ埛涓笉瀛樺湪褰撳墠鐢ㄦ埛
                 {
                     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鐧诲綍鐢ㄦ埛涓笉瀛樺湪褰撳墠鐢ㄦ埛
+            catch (Exception)
             {
                 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") };
             }
+           
         }  
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3