Update rate limits at runtime using WebApiThrottle not working

1

I have a WebApi in ASP.NET MVC and I need to control the access limit, moreover, I need to change the values of the bounds at run time. I have implemented this example on the WebApiThrottle site (section Update rate limits at runtime )

This is the code in my WebApiConfig:

//trace provider
var traceWriter = new SystemDiagnosticsTraceWriter()
{
    IsVerbose = true
};
config.Services.Replace(typeof(ITraceWriter), traceWriter);
config.EnableSystemDiagnosticsTracing();

//Web API throttling handler
config.MessageHandlers.Add(new ThrottlingHandler(
    policy: new ThrottlePolicy(perMinute: 3, perHour: 30, perDay: 35, perWeek: 3000)
    {
        //scope to IPs
        IpThrottling = true,
        //scope to clients
        ClientThrottling = true,
        ClientRules = new Dictionary<string, RateLimits>
        {
            { "client-key-1", new RateLimits { PerMinute = 1, PerHour = 60 } }
        },

        //scope to endpoints
        EndpointThrottling = true
    },

    //replace with PolicyMemoryCacheRepository for Owin self-host
    policyRepository: new PolicyCacheRepository(),

    //replace with MemoryCacheRepository for Owin self-host
    repository: new CacheRepository(),

    logger: new TracingThrottleLogger(traceWriter)));

I'm defining three requisitions per minute as standard and one per-minute requests for the client with the "client-key-1" key. But when I test using PostMan (I'm passing the Authorization token with the client-key-1 value), I noticed that only the default setting is being used because only after three requests did I receive the message:

AndevenifIupdatetheratelimit,usingthefunction:

publicvoidUpdateRateLimits(){//initpolicyrepovarpolicyRepository=newPolicyCacheRepository();//getpolicyobjectfromcachevarpolicy=policyRepository.FirstOrDefault(ThrottleManager.GetPolicyKey());//updateclientratelimitspolicy.ClientRules["client-key-1"] =
        new RateLimits { PerMinute = 20 };

    //apply policy updates
    ThrottleManager.UpdatePolicy(policy, policyRepository);

}

The API calls quota exceeded! maximum admitted 3 per Minute. "continues to appear.

Has anyone ever had this problem?

    
asked by anonymous 27.06.2017 / 23:10

0 answers