asp.net-mvc 简单属性
示例
using System;
using System.Web;
using System.Web.Mvc;
namespace Example.SDK.Filters
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed class CustomErrorHandlerFilter : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
//RouteDate对于检索信息(例如控制器,操作或其他路由值)很有用
string controllerName = filterContext.RouteData.Values["controller"].ToString();
string actionName = filterContext.RouteData.Values["action"].ToString();
string exception = filterContext.Exception.ToString(); //完整的异常堆栈
string message = filterContext.Exception.Message; //异常给出的消息
//在数据库中记录异常
LogExtensions.Insert(exception.ToString(), message, controllerName + "." + actionName);
base.OnException(filterContext);
}
}
}然后放入FilterConfig.cs
filters.Add(new CustomErrorHandlerFilter());
热门推荐
10 分别发的祝福语简短
11 大外甥高考祝福语简短
12 小学毕业校长简短祝福语
13 搞工程发财祝福语简短
14 冬季祝福语男生文案简短
15 同事生子问候祝福语简短
16 退休文案寄语简短祝福语
17 送给自己的祝福语简短
18 简短祝福语毛笔字