Example #1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            SSOClientHelper.CheckSSOConfig();

            var context = HttpContext.Current;

            var user = AppContext.GetObject <LoginStatus>().GetLoginUser(context);

            if (user == null)
            {
                //没有登陆就跳转登陆
                var url          = context.Request.Url.ToString();
                var redirect_url = AppContext.GetObject <IGetLoginUrl>().GetUrl(url);
                filterContext.Result = new RedirectResult(redirect_url);
                return;
            }
            //验证权限
            if (Permission?.Length > 0)
            {
                foreach (var p in Permission.Split(',').Where(x => x?.Length > 0))
                {
                    if (!user.HasPermission(p))
                    {
                        ActionResult re = null;
                        if (ReDirectUrl?.Length > 0)
                        {
                            re = new RedirectResult(ReDirectUrl);
                        }
                        else
                        {
                            re = new JsonResult()
                            {
                                Data = new ResJson()
                                {
                                    Success = false, ErrorMsg = "没有权限", ErrorCode = p
                                },
                                JsonRequestBehavior = JsonRequestBehavior.AllowGet
                            };
                        }
                        filterContext.Result = re;
                        return;
                    }
                }
            }
        }
Example #2
0
 public SSOCheckAttribute()
 {
     SSOClientHelper.CheckSSOConfig();
 }