Exemple #1
0
        protected void HandleException(ExceptionContext filterContext)
        {
            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.StatusCode             = 200;
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;

            if (filterContext.Exception is MessageException)
            {
                filterContext.Result = View("~/Views/App/Error.cshtml", filterContext.Exception);
            }
            else if (filterContext.Exception is MessageException)
            {
                filterContext.Result = View("~/Views/App/Error.cshtml", filterContext.Exception);
            }
            else if (filterContext.Exception is AuthenticationException)
            {
                filterContext.Result = new RedirectResult("/Member/Login");
            }
            else if (filterContext.Exception is AuthorizationException)
            {
                filterContext.Result = View("~/Views/App/Error.cshtml", filterContext.Exception);
            }
            else
            {
                filterContext.Result = View("~/Views/App/Error.cshtml", filterContext.Exception);
                LogUtil.Error($"当前用户:{SessionUtil.MemberId},当前IP:{RequestUtil.GetClientIP()}, 异常信息:{filterContext.Exception.ToString()},请求信息:{RequestUtil.GetRequestInfo()},浏览器信息:{RequestUtil.GetClientBrowserInfo()}");
            }
        }
Exemple #2
0
        protected void HandleAjaxException(ExceptionContext filterContext)
        {
            // 返回的消息格式:
            // Status:0=保留,1=成功,2=提示消息,3=业务异常,300=未登录,400=无权限,500=未知的异常
            // Data:返回的相关异常数据

            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.StatusCode             = 200;
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;

            if (filterContext.Exception is MessageException)
            {
                ContentResult cr = new ContentResult();
                cr.ContentType       = "text/html";
                cr.Content           = "{\"Status\":2,\"Data\":\"" + Server.HtmlEncode(ConvertUtil.Escape(filterContext.Exception.Message)) + "\"}";
                filterContext.Result = cr;
            }
            else if (filterContext.Exception is MessageException)
            {
                ContentResult cr = new ContentResult();
                cr.ContentType       = "text/html";
                cr.Content           = "{\"Status\":3,\"Data\":\"" + Server.HtmlEncode(ConvertUtil.Escape(filterContext.Exception.Message)) + "\"}";
                filterContext.Result = cr;
            }
            else if (filterContext.Exception is AuthenticationException)
            {
                ContentResult cr = new ContentResult();
                cr.ContentType       = "text/html";
                cr.Content           = "{\"Status\":300,\"Data\":\"" + Server.HtmlEncode(ConvertUtil.Escape(filterContext.Exception.Message)) + "\"}";
                filterContext.Result = cr;
            }
            else if (filterContext.Exception is AuthorizationException)
            {
                ContentResult cr = new ContentResult();
                cr.ContentType       = "text/html";
                cr.Content           = "{\"Status\":400,\"Data\":\"" + Server.HtmlEncode(ConvertUtil.Escape(filterContext.Exception.Message)) + "\"}";
                filterContext.Result = cr;
            }
            else
            {
                ContentResult cr = new ContentResult();
                cr.ContentType       = "text/html";
                cr.Content           = "{\"Status\":500,\"Data\":\"" + Server.HtmlEncode(ConvertUtil.Escape(filterContext.Exception.Message)).Replace(@"\"", "") + "\"}";
                filterContext.Result = cr;

                LogUtil.Error($"当前用户:{SessionUtil.MemberId},当前IP:{RequestUtil.GetClientIP()}, 异常信息:{filterContext.Exception.ToString()},请求信息:{RequestUtil.GetRequestInfo()},浏览器信息:{RequestUtil.GetClientBrowserInfo()}");
            }
        }