Exemple #1
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower();
            var actionName     = filterContext.ActionDescriptor.ActionName.ToLower();

            if (controllerName == "account" && (actionName == "login" || actionName == "getcheckcode"))
            {
                return;
            }
            var isAjaxRequst = filterContext.HttpContext.Request.IsAjaxRequest();

            #region 验证登录
            TResult result = new TResult();
            if (UserInfo == null)
            {
                if (filterContext.HttpContext.Request.IsAjaxRequest())
                {
                    filterContext.Result = Json(result.RequestAuthorizeResult("登录失效,请刷新页面"), JsonRequestBehavior.AllowGet);
                    return;
                }
                filterContext.Result = new RedirectResult("/Login/Index");
                return;
            }
            #endregion
        }