簡體   English   中英

WebApiThrottle 不阻止任何請求

[英]WebApiThrottle not blocking any requests

標題真的說明了一切。

我正在使用https://github.com/stefanprodan/WebApiThrottle來控制對我的 webApi 的請求數量,只是它不是..

我已經降低了 lints 的速率,以確保我絕對不會只是發送請求太慢。

我無緣無故切換了Repository ,以防萬一。 我已刪除並添加了EndpointRules

我所做的一切似乎都沒有任何效果。

完整的 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()
        });  
    }
}

任何人都可以看到任何明顯錯誤的東西嗎?

我將不得不猜測這是一個緩存思考/開發人員錯誤。 在某些時候它才開始工作,我每秒 1 次的規則基本上關閉了我的 API - 哎呀!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM