解决方法
我不记得我从哪里得到这个,但是我正在寻找类似的东西,发现一个文章或某处包含这个记录过滤器的东西:
public class LogActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { Log("OnActionExecuting",filterContext.RouteData); } public override void OnActionExecuted(ActionExecutedContext filterContext) { Log("OnActionExecuted",filterContext.RouteData); } public override void OnResultExecuting(ResultExecutingContext filterContext) { Log("OnResultExecuting",filterContext.RouteData); } public override void OnResultExecuted(ResultExecutedContext filterContext) { Log("OnResultExecuted",filterContext.RouteData); } private void Log(string methodName,RouteData routeData) { var controllerName = routeData.Values["controller"]; var actionName = routeData.Values["action"]; var message = string.Format("{0} controller: {1} action: {2}",methodName,controllerName,actionName); Debug.WriteLine(message,"Action Filter Log"); } }
要使用它,只需将其添加到global.asax中的全局过滤器:
public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); filters.Add(new LogActionFilter()); }
我现在来看看是否可以找到源.
编辑:找到它.是从this question.