public override void OnException(ExceptionContext filterContext) { base.OnException(filterContext); ErrorMessage msg = new ErrorMessage(filterContext.Exception, "页面"); msg.ShowException = MvcException.IsExceptionEnabled(); //错误记录 LogHelper.WriteLog(JsonConvert.SerializeObject(msg, Formatting.Indented), null); //设置为true阻止golbal里面的错误执行 filterContext.ExceptionHandled = true; filterContext.Result = new ViewResult() { ViewName = "/Views/Error/ISE.cshtml", 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); LogHelper.WriteLog(exMsg, null); filterContext.Response = new HttpResponseMessage() { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(exMsg) }; }