private void HandleUnauthorizedRequest(
            AuthorizationContext filterContext,
            MethodInfo methodInfo,
            AbpAuthorizationException ex)
        {
            filterContext.HttpContext.Response.StatusCode =
                filterContext.RequestContext.HttpContext.User?.Identity?.IsAuthenticated ?? false
                    ? (int) HttpStatusCode.Forbidden
                    : (int) HttpStatusCode.Unauthorized;

            var isJsonResult = MethodInfoHelper.IsJsonResult(methodInfo);

            if (isJsonResult)
            {
                filterContext.Result = new AbpJsonResult(
                    new AjaxResponse(
                        _errorInfoBuilder.BuildForException(ex)
                    )
                ) {JsonRequestBehavior = JsonRequestBehavior.AllowGet};
            }
            else
            {
                filterContext.Result = new HttpStatusCodeResult(filterContext.HttpContext.Response.StatusCode, ex.Message);
            }

            if (isJsonResult || filterContext.HttpContext.Request.IsAjaxRequest())
            {
                filterContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;
            }
        }
        protected virtual void HandleUnauthorizedRequest(
            AuthorizationContext filterContext, 
            MethodInfo methodInfo, 
            AbpAuthorizationException ex)
        {
            filterContext.HttpContext.Response.StatusCode =
                filterContext.RequestContext.HttpContext.User?.Identity?.IsAuthenticated ?? false
                    ? (int) HttpStatusCode.Forbidden
                    : (int) HttpStatusCode.Unauthorized;

            var isJsonResult = MethodInfoHelper.IsJsonResult(methodInfo);

            if (isJsonResult)
            {
                filterContext.Result = CreateUnAuthorizedJsonResult(ex);
            }
            else
            {
                filterContext.Result = CreateUnAuthorizedNonJsonResult(filterContext, ex);
            }

            if (isJsonResult || filterContext.HttpContext.Request.IsAjaxRequest())
            {
                filterContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;
            }

            _eventBus.Trigger(this, new AbpHandledExceptionData(ex));
        }
 protected virtual AbpJsonResult CreateUnAuthorizedJsonResult(AbpAuthorizationException ex)
 {
     return new AbpJsonResult(
         new AjaxResponse(_errorInfoBuilder.BuildForException(ex), true))
         {
             JsonRequestBehavior = JsonRequestBehavior.AllowGet
         };
 }
 protected virtual HttpStatusCodeResult CreateUnAuthorizedNonJsonResult(AuthorizationContext filterContext, AbpAuthorizationException ex)
 {
     return new HttpStatusCodeResult(filterContext.HttpContext.Response.StatusCode, ex.Message);
 }