自定义异常处理过滤器
来源:互联网 发布:淘宝代收货怎么没了 编辑:程序博客网 时间:2024/05/17 06:57
自定义异常处理过滤器public class WebRequestErrorEventMvc : WebRequestErrorEvent { public WebRequestErrorEventMvc(string message, object eventSource, int eventCode, Exception exception) : base(message, eventSource, eventCode, exception) { } public WebRequestErrorEventMvc(string message, object eventSource, int eventCode, int eventDetailCode, Exception exception) : base(message, eventSource, eventCode, eventDetailCode, exception) { } }public class MyHandleErrorAttribute : HandleErrorAttribute { public override void OnException(ExceptionContext filterContext) { base.OnException(filterContext); int MvcEventCode = WebEventCodes.WebExtendedBase + 1; WebRequestErrorEventMvc webRequestErrorEventMvc = new WebRequestErrorEventMvc("An unhandled exception has occurred.", this, MvcEventCode, filterContext.Exception); webRequestErrorEventMvc.Raise(); string body ="Error is occured at the request :"+ webRequestErrorEventMvc.RequestInformation.RequestUrl; SendMail("spencergong","yaya1234","spencergong@gmail.com","spencergong@yahoo.com", "Email from MyHandlerError ", body); } bool SendMail(string userName,string passWord, string from, string to, string subject, string body) { SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); smtp.Credentials = new NetworkCredential(userName, passWord ); smtp.EnableSsl = true; MailMessage message = new MailMessage(new MailAddress ( from ), new MailAddress( to)); message.Body = body ; message.Subject =subject; try { smtp.Send (message); return true; } catch (Exception ex ) { return false; } }}设置web.config配置文件
- 自定义异常处理过滤器
- MVC WebApi自定义异常过滤器
- MVC 自定义过滤器(Filter)实现路由控制、异常处理、授权处理(获取客户端信息)
- 异常处理+异常+处理异常+自定义异常
- Java异常处理-----自定义异常
- Java异常处理--自定义异常
- netty自定义url过滤器抛引用异常
- VB自定义异常处理
- 自定义异常处理
- 自定义异常处理
- PHP自定义异常处理
- 自定义异常处理
- 自定义异常处理类
- 自定义异常处理
- 自定义异常处理错误信息
- set_exception_handler 自定义异常处理
- C#自定义异常处理
- 自定义C++异常处理
- oracle常用视图
- Google C++编程风格指南(四):智能指针和其他C++特性
- 常见音频格式面面观
- 测试工具的选择和使用
- Google C++编程风格指南(五):命名约定
- 自定义异常处理过滤器
- Google C++编程风格指南(六):代码注释
- CSS的hack解决积累
- javascript:获取屏幕高度和宽度等信息 & 制作滚动窗体时遇到的问题
- Ext.form.ComboBox简单用法
- 我的开始
- ATPCS
- Google C++编程风格指南(八):规则之例外
- Google C++编程风格指南(七):格式