question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rate limit policy settings is not applied using AspNetCoreRateLimit in .net core 6

See original GitHub issue

Hi, I am using AspNetCoreRateLimit version 4.0.1 and I have done all the setup in .net core 6 web api. I can see rate limit is working when I send a call via postman.

However, when I add IpRateLimitPolicies with specific IP address, the settings won’t be applied. I use postman and this time in the proxy I added the ip address to 127.0.0.1. I can see the ip hitting the api is set correctly when I use Request.HttpContext.Connection.RemoteIpAddress; I also deployed to our dev environment and called from a different client and got the same result.

I registered them as follow in program.cs: _serviceCollection.AddOptions(); _serviceCollection.AddMemoryCache(); _serviceCollection.Configure<IpRateLimitOptions>(builder.Configuration.GetSection("IpRateLimiting")); _serviceCollection.Configure<IpRateLimitPolicies>(builder.Configuration.GetSection("IpRateLimitPolicies")); _serviceCollection.AddInMemoryRateLimiting(); _serviceCollection.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>(); _serviceCollection.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>(); _serviceCollection.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); _serviceCollection.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();

Also added: app.UseIpRateLimiting();

My appsettings also looks like: { "IpRateLimiting": { "EnableEndpointRateLimiting": false, "StackBlockedRequests": false, "RealIPHeader": "X-Real-IP", "ClientIdHeader": "X-ClientId", "IpWhitelist": [ ], "EndpointWhitelist": [], "ClientWhitelist": [], "HttpStatusCode": 429, "GeneralRules": [ { "Endpoint": "*", "Period": "10s", "Limit": 1 } ] }, "IpRateLimitPolicies": { "IpRules": [ { "Ip": "127.0.0.1", "Rules": [ { "Endpoint": "*", "Period": "20s", "Limit": 2 } ] } ] }

But apparently the settings under IpRateLimitPolicies won’t be applied.

I wonder if I have missed anything here?

Thank you

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:13

github_iconTop GitHub Comments

3reactions
ghostcommented, Feb 19, 2022

Same issue here, my ratelimit rules are not applying either

2reactions
MAYBreathcommented, Feb 26, 2022

IpRateLimitPolicies

@arash3003 yes,you need add those code at Program.cs var ipPolicyStore = app.Services.GetRequiredService<IIpPolicyStore>(); ipPolicyStore.SeedAsync().GetAwaiter().GetResult(); var clientPolicyStore = app.Services.GetRequiredService<IClientPolicyStore>(); clientPolicyStore.SeedAsync().GetAwaiter().GetResult();

and if you test at localhost,try change “Ip”: “127.0.0.1” to “Ip”: “::1/10” ,it may help you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rate limit policy settings is not applied using ...
I am using AspNetCoreRateLimit version 4.0.1 and I have done all the setup in .net core 6 web api. I can see rate...
Read more >
Rate Limiting In .NET 6.0
The limitation on the number of requests to each API endpoint can be applied to each unique user/IP address/client. Purpose of Rate Limiting?...
Read more >
Rate limiting middleware in ASP.NET Core
RateLimiting middleware provides rate limiting middleware. Apps configure rate limiting policies and then attach the policies to endpoints. Apps ...
Read more >
Implementing Rate Limiting in ASP.NET 6 Core and C# ...
In this article, we've implemented client rate limiting using the AspNetCoreRateLimit package in ASP.NET 6.
Read more >
Built-in rate limiting in ASP.NET Core vs ... - elmah.io Blog
In this case, we want rate limiting to apply. If not, rate limiting should not be run which is done by returning the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found