asp.net mvc全局异常捕获
通过重写OnException方法形式实现。
1、自定义异常记录类并继承HandleErrorAttribute类。
public class HandlerErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext context)
{
base.OnException(context);
//context.ExceptionHandled = true; WriteLog(context);
var url = context.HttpContext.Request.Path;
var msg = url + context.Exception.Message;
new LogApp().WriteDbLog(msg);
} private void WriteLog(ExceptionContext context)
{
if (context == null)
return;
var log = LogFactory.GetLogger(context.Controller.ToString());
log.Error(context.Exception);
}
}
2、修改原有FilterConfig文件,使其添加新添加的HandlerErrorAttribute类。
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandlerErrorAttribute());
}
}
3、Global.asax中注册(默认已注册过滤器)。
public class MvcApplication : System.Web.HttpApplication
{
/// <summary>
/// 启动应用程序
/// </summary>
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
asp.net mvc全局异常捕获的更多相关文章
- ASP.NET MVC 全局异常
先新建一个过滤器ExceptionHandleErrorAttribute.cs 内容如下: using System; using System.Net; using System.Web; usi ...
- Asp.Net MVC3(三)-MvcApp实现全局异常捕获
定义异常捕获类: [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMu ...
- MVC 好记星不如烂笔头之 ---> 全局异常捕获以及ACTION捕获
public class BaseController : Controller { /// <summary> /// Called after the action method is ...
- Asp.net Core全局异常监控和记录日志
前言 系统异常监控可以说是重中之重,系统不可能一直运行良好,开发和运维也不可能24小时盯着系统,系统抛异常后我们应当在第一时间收到异常信息.在Asp.net Core里我使用拦截器 ...
- C#中的那些全局异常捕获
1.WPF全局捕获异常 public partial class App : Application { public App() { // 在异 ...
- Spring-MVC开发之全局异常捕获全面解读
异常,异常 我们一定要捕获一切该死的异常,宁可错杀一千也不能放过一个! 产品上线后的异常更要命,一定要屏蔽错误内容,以免暴露敏感信息! 在用Spring MVC开发WEB应用时捕获全局异常的方法基本有 ...
- 使用spring利用HandlerExceptionResolver实现全局异常捕获
最近一直没有时间更新是因为一直在更新自己使用的框架. 之后会慢慢带来对之前使用的spring+mvc+mybatis的优化. 会使用一些新的特性,实现一些新的功能. 我会尽量分离业务,封装好再拿出来. ...
- (转)C#中的那些全局异常捕获
C#中的那些全局异常捕获(原文链接:http://www.cnblogs.com/taomylife/p/4528179.html) 1.WPF全局捕获异常 public partia ...
- spring boot: GlobalDefaultExceptionHandler方法内的友好错误提示,全局异常捕获
spring boot: GlobalDefaultExceptionHandler方法内的友好错误提示,全局异常捕获 当你的某个控制器内的某个方法报错,基本上回显示出java错误代码,非常不友好,这 ...
随机推荐
- WordPress无法发送电子邮件,可能原因:您的主机禁用了mail()函数解决方案
体验更优排版请移步原文:http://blog.kwin.wang/website/wp-cant-send-email-solution.html 最近折腾了下WordPress,给米表 搭了个论坛 ...
- Changing the load order/delay the start of the Server service
THE INFORMATION IN THIS ARTICLE APPLIES TO: Secure FTP Server (All Versions) EFT Server (All Version ...
- UNITY 手动定制inspector
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; us ...
- DOCKER windows 7 详细安装教程
DOCKER windows安装 编者: xiaym 日期:2015年1月20日 排版工具: 马克飞象 QQ: 252536711 DOCKER windows安装 1.下载程序包 2. 设置环境变量 ...
- python之with...as
[python之with...as] 参考:http://python.42qu.com/11155501
- EmEditor的正则表达式
前提是 "使用正则表达式"的复选框打上勾. 1 查找<>之间的字符串: ".*?"2 查找双引号之间的字符串: ".*?" ...
- 第七章 二叉搜索树(b1)BST:查找
- Element DatePicker日期范围选择
前7天后7天 <el-date-picker v-model="value1" type="date" :picker-options="pic ...
- asp.net页如何获取母版页控件
获取母版页的相关内容有两种方法 1 通过findcontrol找控件ID需要在此事件中~因为Page_load中时是先内容页加载然后才是母版页加载 protected void Page_LoadCo ...
- input checkbox 复选框大小修改
设置zoom属性(放大) 利用style: <input type="checkbox" name="returnfee" style="zo ...