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());
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西