chenpeng

C#MVC代码防刷新类库
由于类库不能上传所有有需要的请留言或者加联系方式qq739989440[EnableThrottling(PerS...
扫描右侧二维码阅读全文
22
2019/08

C#MVC代码防刷新类库

由于类库不能上传所有有需要的请留言或者加联系方式qq739989440

[EnableThrottling(PerSecond = 5, PerMinute = 10)]

这是类库的使用方法引用项目直接复制这句话。

public class FilterConfig
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            const int secondCount = 5;
            var throttleFilter = new ThrottlingFilter
            {
                //每秒钟最多请求secondCount次,每分钟最多请求secondCount*60次,依次类推

                Policy = new ThrottlePolicy(
                    perSecond: secondCount,
                    perMinute: secondCount * 10,
                    perHour: secondCount * 10 * 5,
                    perDay: secondCount * 10 * 5 * 2)
                {
                    IpThrottling = true
                },
                Repository = new CacheRepository()
            };
            filters.Add(throttleFilter);

            filters.Add(new HandleErrorAttribute());
        }

以上是FilterConfig的配置方法也是应用类库直接复制就好了

在Global中Application_Start方法中加入FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

Last modification:August 22nd, 2019 at 12:31 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment