简体   繁体   English

WebApiThrottle 不阻止任何请求

[英]WebApiThrottle not blocking any requests

Title says it all really.标题真的说明了一切。

I'm using https://github.com/stefanprodan/WebApiThrottle to control the number of requests to my webApi, only its not..我正在使用https://github.com/stefanprodan/WebApiThrottle来控制对我的 webApi 的请求数量,只是它不是..

I have screwed down the rate lints to ensure that I'm definitely not just sending my requests too slow.我已经降低了 lints 的速率,以确保我绝对不会只是发送请求太慢。

I have switched the Repository for no reason other than, just in case.我无缘无故切换了Repository ,以防万一。 I have removed and added EndpointRules我已删除并添加了EndpointRules

Nothing I do seems to have any effect.我所做的一切似乎都没有任何效果。

The full WebApiConfig file is here:完整的 WebApiConfig 文件在这里:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services - moved to web.config
        var cors = new EnableCorsAttribute(origins: "*", headers: "*", methods: "*");
        config.EnableCors(cors);

        // Web API routes
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        // API throttling - https://github.com/stefanprodan/WebApiThrottle
        config.MessageHandlers.Add(new ThrottlingHandler()
        {
            Policy = new ThrottlePolicy(perSecond: 1, perMinute: 1, perHour: 1) // (perSecond: 1, perMinute: 20, perHour: 200)
            {
                IpThrottling = true,
                ClientThrottling = true,
                EndpointThrottling = true,
                EndpointRules = new Dictionary<string, RateLimits>
                {
                    { "/search/", new RateLimits { PerSecond = 1, PerMinute = 1, PerHour = 1 } }
                }
            },
            Repository = new MemoryCacheRepository() //CacheRepository()
        });  
    }
}

Can anyone see anything thats obviously wrong?任何人都可以看到任何明显错误的东西吗?

I'm going to have to guess it was a cache think / developer error.我将不得不猜测这是一个缓存思考/开发人员错误。 At some point it just started working and my 1 per second rule basically turned off my API - whoops!在某些时候它才开始工作,我每秒 1 次的规则基本上关闭了我的 API - 哎呀!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM