Пример #1
0
        public override ActionResult OnActionExecuting()
        {
            var result = string.Empty;

            try
            {
                if (HttpContext.Current.Request.Headers.ContainsKey("Authorization"))
                {
                    var val = HttpContext.Current.Request.Headers["Authorization"].ToString();

                    val = val.Replace(JWTPackage.Prex, "");

                    _jwt = JWTPackage <UserInfo> .Parse(val, _pwd);

                    HttpContext.Current.Session["userInfo"] = _jwt;

                    result = "OK";
                }
            }
            catch (IllegalTokenException iex)
            {
                result = $"解析失败:{iex.Message}";
            }
            catch (TokenExpiredException tex)
            {
                result = $"解析失败:{tex.Message}";
            }
            catch (SignatureVerificationException sex)
            {
                result = $"解析失败:{sex.Message}";
            }
            catch (Exception ex)
            {
                result = $"解析失败:{ex.Message}";
            }
            if (result == "OK")
            {
                return(EmptyResult.Default);
            }
            else
            {
                result = $"解析失败,缺少jwt token";
            }
            return(ContentResult.Get(result));
        }
Пример #2
0
        public override bool OnActionExecuting()
        {
            var result = string.Empty;

            try
            {
                if (HttpContext.Current.Request.Headers.ContainsKey("Authorization"))
                {
                    var val = HttpContext.Current.Request.Headers["Authorization"].ToString();

                    val = val.Replace(JWTPackage.Prex, "");

                    _jwt = JWTPackage <UserInfo> .Parse(val, _pwd);

                    HttpContext.Current.Session["userInfo"] = _jwt;

                    result = "OK";
                }
            }
            catch (IllegalTokenException iex)
            {
                result = $"解析失败:{iex.Message}";
            }
            catch (TokenExpiredException tex)
            {
                result = $"解析失败:{tex.Message}";
            }
            catch (SignatureVerificationException sex)
            {
                result = $"解析失败:{sex.Message}";
            }
            catch (Exception ex)
            {
                result = $"解析失败:{ex.Message}";
            }
            if (result == "OK")
            {
                return(true);
            }
            else
            {
                LogHelper.Error("jwt签权失败", new Exception(result));
            }
            return(false);
        }