要实现给mvc 和api 接口全局添加日志统计,web api添加的方式有些不同
FilterConfig.cs 页面 public class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new AuthorizeAttribute()); filters.Add(new HandleErrorAttribute()); } public static void RegisterWebApiGlobalFilters(HttpFilterCollection filters) { filters.Add(new LogApiFilter()); } } Global.asax 页面 protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); GlobalFilters.Filters.Add(new LogMvcFilte()); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); FilterConfig.RegisterWebApiGlobalFilters(GlobalConfiguration.Configuration.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //定义定时器 // _timer = new Timer(TimerCircle_Callback, null, 0, Timeout.Infinite); }
http://stackoverflow.com/questions/9521040/how-to-add-global-asp-net-web-api-filters