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 夜雨祝福语简短10字
16 蛋糕祝福语简短闺蜜
17 部门过年祝福语简短独特
18 简短精炼的结婚祝福语