Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rate limiting is not working for with .net6 and AspNetCoreRateLimit 5.0 #449

Open
karthikchintala1 opened this issue Aug 9, 2023 · 1 comment

Comments

@karthikchintala1
Copy link

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

@karthikchintala1 karthikchintala1 changed the title rate limiting is not working for me with .net6 and AspNetCoreRateLimit 5.0 rate limiting is not working for with .net6 and AspNetCoreRateLimit 5.0 Aug 9, 2023
@eduardocalixtokorp
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants