Esempio n. 1
0
        //加上如下的重写方法,在方法内进行跳转,问题解决
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            if (_IsNoPermissionToAccess)
            {
                filterContext.Result = new JsonResult()
                {
                    Data                = ResponseModel <string> .Invalid(MessageHelper.NoPermissionToAccess),
                    ContentEncoding     = System.Text.Encoding.UTF8,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
                return;
            }

            string url = $"{_LoginUri}?returnURL=";

            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                url += HttpUtility.UrlEncode(filterContext.HttpContext.Request.UrlReferrer.ToString());
                filterContext.Result = new JsonResult()
                {
                    Data                = ResponseModel <string> .Logout(url, MessageHelper.NoSession),
                    ContentEncoding     = System.Text.Encoding.UTF8,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
            }
            else
            {
                url += HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString());
                filterContext.Result = new RedirectResult(url);
            }
        }
Esempio n. 2
0
        //加上如下的重写方法,在方法内进行跳转,问题解决
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            base.HandleUnauthorizedRequest(filterContext);

            string url = $"{_LoginUri}?returnURL=";

            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                url += HttpUtility.UrlEncode(filterContext.HttpContext.Request.UrlReferrer.ToString());
                filterContext.Result = new JsonResult()
                {
                    Data                = ResponseModel <string> .Logout(url),
                    ContentEncoding     = System.Text.Encoding.UTF8,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };
            }
            else
            {
                url += HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.ToString());
                filterContext.Result = new RedirectResult(url);
            }
        }
        public override void OnException(ExceptionContext filterContext)
        {
            filterContext.ExceptionHandled = true;

            LogHelper.Error(filterContext.Exception);

            bool bIsEFException = filterContext.Exception is EntityException;

            if (bIsEFException)
            {
                SiteHelper.RestartAppDomain();
            }

            string strErrorMsg = bIsEFException ? EF_ERROR : GetExceptionType(filterContext.Exception);

            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                JsonNetResult jsonResult = new JsonNetResult
                {
                    Data = bIsEFException ? ResponseModel <string> .Logout("/", strErrorMsg) : ResponseModel <string> .Error(strErrorMsg),
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                };

                filterContext.Result = jsonResult;
                return;
            }

            var result = new ViewResult()
            {
                ViewName = "Error"
            };

            result.ViewBag.Error     = strErrorMsg;
            result.ViewBag.IsRestart = bIsEFException;
            filterContext.Result     = result;
        }