码迷,mamicode.com
首页 > Windows程序 > 详细

how-to-add-global-asp-net-web-api-filters

时间:2015-09-15 18:00:50      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:

要实现给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

how-to-add-global-asp-net-web-api-filters

标签:

原文地址:http://www.cnblogs.com/wellma/p/4810620.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!