AspNetCoreRateLimit
AspNetCoreRateLimit copied to clipboard
4.0 Breaking Change Wiki out of date
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!
Me too, thanks for your help.
+1 for 4.0 breaking changes document
@lacutah Thanks for pointing out the breaking change, fix. +1 for 4.0 breaking changes doc.
+1 for RateLimitConfiguration and IClientResolveContributor docs in 4.X
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 have you figured it out? Would be wonderful if you could share your results.
@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 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