using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using cpf360.Common; using cpf360.DTO; namespace hanli_project.Filters { public class HanliExceptionAttribute : IExceptionFilter { void IExceptionFilter.OnException(ExceptionContext filterContext) { Exception exception = filterContext.Exception; if (filterContext.ExceptionHandled) { return; } //返回数据 filterContext.Result = new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new OutputData() { data = null, code = -1, message = "服务器繁忙" } }; //记录日志 Log4netHelper.LogError(exception); // 设置自定义异常已经处理,避免其他过滤器异常覆盖 filterContext.ExceptionHandled = true; // 在派生类重写时,设置或者重写一个值该值指定是否禁用ISS7.0中自定义错误 filterContext.HttpContext.Response.TrySkipIisCustomErrors = true; } } }
using System.Web; using System.Web.Mvc; using hanli_project.Filters; namespace hanli_project { public class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { //注册异常过滤器 filters.Add(new HanliExceptionAttribute()); filters.Add(new HandleErrorAttribute()); } } }
原文地址:https://www.cnblogs.com/chenyishi/p/8876026.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。