AspNetCoreRateLimit icon indicating copy to clipboard operation
AspNetCoreRateLimit copied to clipboard

4.0 Breaking Change Wiki out of date

Open lacutah opened this issue 3 years ago • 8 comments

I guess I got lucky and updated my project references first and had to wade through the test code to find out what was missing... I have no clue how to submit pull request for a wiki, LOL.

Might want a 4.0 breaking changes document along with 3.0 breaking changes.

Wiki examples needs updated to show (this is missing):

// register stores
services.AddInMemoryRateLimiting();
// OR
// services.AddDistributedRateLimiting<AsyncKeyLockProcessingStrategy>();

The two pages: https://github.com/stefanprodan/AspNetCoreRateLimit/wiki/ClientRateLimitMiddleware#setup https://github.com/stefanprodan/AspNetCoreRateLimit/wiki/IpRateLimitMiddleware

Thanks for the great package!

lacutah avatar May 26 '21 03:05 lacutah

Me too, thanks for your help.

hedronn avatar May 26 '21 07:05 hedronn

+1 for 4.0 breaking changes document

ghost avatar Jun 08 '21 08:06 ghost

@lacutah Thanks for pointing out the breaking change, fix. +1 for 4.0 breaking changes doc.

mayne92 avatar Jun 22 '21 01:06 mayne92

+1 for RateLimitConfiguration and IClientResolveContributor docs in 4.X

rebeccapowell avatar Jul 09 '21 20:07 rebeccapowell

Until there are no official docs, can someone share a working example of Client rate limiting using Redis?

services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimiting"));
services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies"));

//load general configuration from appsettings.json
services.Configure<ClientRateLimitOptions>(Configuration.GetSection("ClientRateLimiting"));
services.Configure<ClientRateLimitPolicies>(Configuration.GetSection("ClientRateLimitPolicies"));

services.AddDistributedRateLimiting<AsyncKeyLockProcessingStrategy>();
services.AddDistributedRateLimiting<RedisProcessingStrategy>();
services.AddSingleton<IIpPolicyStore, DistributedCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, DistributedCacheRateLimitCounterStore>();

var redisOptions = ConfigurationOptions.Parse(Configuration["ConnectionStrings:Redis"]);
services.AddSingleton<IConnectionMultiplexer>(provider => ConnectionMultiplexer.Connect(redisOptions));
services.AddRedisRateLimiting();

services.AddSingleton<IRateLimitConfiguration, CustomRateLimitConfiguration>();

I am getting this error: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: AspNetCoreRateLimit.IIpPolicyStore Lifetime: Singleton ImplementationType: AspNetCoreRateLimit.DistributedCacheIpPolicyStore

Current documentation is confusing version v3 vs v4

deivyd321 avatar Aug 06 '21 06:08 deivyd321

@deivyd321 have you figured it out? Would be wonderful if you could share your results.

timonmasberg avatar Mar 29 '22 15:03 timonmasberg

@deivyd321 have you figured it out? Would be wonderful if you could share your results.

Have you found any way to solve this issue? I'm still getting it :/

madebyluque avatar Jan 17 '23 01:01 madebyluque

@madebyluque This is the implementation I have for my .NET 6 API using IP Rate Limiting with Azure Redis Cache. I have not tested this in a load balancer setup as yet, only a single server development environment. But if this works for you in a cluster environment I would be grateful for the confirmation.

[Nuget Packages]

AspNetCoreRateLimit 5.0.0 StackExchange.Redis 2.2.4

[Startup.cs]

public void ConfigureServices(IServiceCollection services) { ...

services.AddDistributedRateLimiting<AsyncKeyLockProcessingStrategy>(); services.AddStackExchangeRedisCache(option => { option.Configuration = Configuration["RedisCache:ConnectionString"]; option.InstanceName = "RedisCacheInstanceName"; });

services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimiting")); services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies"));

services.AddSingleton<IIpPolicyStore, DistributedCacheIpPolicyStore>(); services.AddSingleton<IRateLimitCounterStore, DistributedCacheRateLimitCounterStore>(); services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();

... }

public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { ...

app.UseIpRateLimiting();

... }

---------- Throttled Response -------- Error: response status is 429

{ "message": "Status code: 429", "details": "API call quota exceeded" }

Hope this helps

hedronn avatar Jan 17 '23 08:01 hedronn