예제 #1
0
        public override void OnException(ExceptionContext context)
        {
            if (!_hostingEnvironment.IsDevelopment())
            {
                // do nothing
                return;
            }
            if (context.Exception == null)
            {
                return;
            }
            MvcException me = (MvcException)context.Exception;

            switch (me.HttpErrorCode)
            {
            case 404:
                context.Result = new NotFoundObjectResult(context.Exception.Message);
                break;

            default:
                context.Result = new BadRequestObjectResult(context.Exception.Message);
                break;
            }
            //context.Result = new BadRequestObjectResult(context.Exception.Message);
        }
예제 #2
0
        public override void OnException(ExceptionContext filterContext)
        {
            base.OnException(filterContext);

            ErrorMessage msg = new ErrorMessage(filterContext.Exception, "页面");

            msg.ShowException = MvcException.IsExceptionEnabled();

            var log = new LogHelper();

            log.LogError("被系统过滤捕获的异常" + filterContext.Exception);

            //设置为true阻止golbal里面的错误执行
            filterContext.ExceptionHandled = true;
            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                filterContext.Result = new JsonResult()
                {
                    Data = new ResultEntity()
                    {
                        result = false, message = "服务器异常,联系管理员或查看错误日志!"
                    }
                }
            }
            ;
            else
            {
                filterContext.Result = new ViewResult()
                {
                    ViewName = "ISE", ViewData = new ViewDataDictionary <ErrorMessage>(msg)
                }
            };
        }
    }
예제 #3
0
        private static Exception wrapStaticFileException(Exception ex)
        {
            if (ex.TargetSite.DeclaringType.FullName.Equals("System.Web.StaticFileHandler") == false)
            {
                return(ex);
            }

            MvcException mvcEx = new MvcException(lang.get("NotFound404"), ex.InnerException == null ? ex : ex.InnerException);

            mvcEx.Status = HttpStatus.NotFound_404;
            return(mvcEx);
        }
예제 #4
0
        private int getErrorStatus()
        {
            if (ex != null)
            {
                MvcException mvcEx = ex as MvcException;
                if (mvcEx != null && mvcEx.hasStatus())
                {
                    return(mvcEx.getStatusCode());
                }
            }

            return(0);
        }
예제 #5
0
        public override void OnException(HttpActionExecutedContext filterContext)
        {
            base.OnException(filterContext);

            //异常信息
            ErrorMessage msg = new ErrorMessage(filterContext.Exception, "接口");

            //接口调用参数
            msg.ActionArguments = JsonConvert.SerializeObject(filterContext.ActionContext.ActionArguments, Formatting.Indented);
            msg.ShowException   = MvcException.IsExceptionEnabled();

            //错误记录
            string exMsg = JsonConvert.SerializeObject(msg, Formatting.Indented);

            var log = new LogHelper();

            log.LogError("被系统过滤捕获的异常" + exMsg);

            filterContext.Response = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(exMsg)
            };
        }