rate limiting is not working for with .net6 and AspNetCoreRateLimit 5.0
karthikchintala1 opened this issue · 1 comments
karthikchintala1 commented
I'm trying to setup rate limiting for my app but unfortunately it's not working as expected. In the below example, I've setup a limit to 1 under 1 min. But, I'm able to make multiple requests to the API's wthin the timeframe.
Here is my startup.cs file
builder.Services.AddOptions();
// needed to store rate limit counters and ip rules
builder.Services.AddMemoryCache();
//load general configuration from appsettings.json
builder.Services.Configure<ClientRateLimitOptions>(builder.Configuration.GetSection("ClientRateLimiting"));
builder.Services.AddMemoryCache();
builder.Services.AddInMemoryRateLimiting();
// Add framework Services.
builder.Services.AddMvc(option => option.EnableEndpointRouting = false);
// configuration (resolvers, counter key builders)
builder.Services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
var app = builder.Build();
app.UseClientRateLimiting();
app.UseMvc();
await app.RunAsync();
and here is my appsettings.json file
{
"ClientRateLimiting": {
"EnableEndpointRateLimiting": false,
"StackBlockedRequests": false,
"ClientIdHeader": "X-ClientId",
"HttpStatusCode": 429,
"GeneralRules": [
{
"Endpoint": "*",
"Period": "1m",
"Limit": 1
}
]
}
}
I've looked on stack overflow and googled a bit but couldn't find anything helpful.
Frameworks and libraries:
.NET 6 API,
AspNetCoreRateLimit 5.0.0
eduardocalixtokorp commented
It might not help you, but I recently tested UseClientRateLimiting in net 6.0 and it was working just fine, I've been having problemas only with UseIpRateLimiting. The only difference was that I set "EnableEndpointRateLimiting": true