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) } }; } }
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) }; }