I installed AspNetCoreRateLimit and am trying to get it configured properly, but It's not having any effect on the API.
In Startup.cs, in ConfigureServices() I added this
#region AspNetCoreRateLimit
// needed to load configuration from appsettings.json
services.AddOptions();
// needed to store rate limit counters and ip rules
services.AddMemoryCache();
//load general configuration from appsettings.json
services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimiting"));
// inject counter and rules stores
services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
// Add framework services.
services.AddMvc();
// https://github.com/aspnet/Hosting/issues/793
// the IHttpContextAccessor service is not registered by default.
// the clientId/clientIp resolvers use it.
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
// configuration (resolvers, counter key builders)
services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
#endregion AspNetCoreRateLimit
and in Configure() of the same file I put
app.UseIpRateLimiting();
In appsettings.json I added this section, making sure it's in the object root
"IpRateLimiting": {
"EnableEndpointRateLimiting": true,
"StackBlockedRequests": false,
"RealIpHeader": "X-Real-IP",
"ClientIdHeader": "X-ClientId",
"HttpStatusCode": 429,
//"IpWhitelist": [ "127.0.0.1", "::1/10", "192.168.0.0/24" ],
//"EndpointWhitelist": [ "get:/api/license", "*:/api/status" ],
//"ClientWhitelist": [ "dev-id-1", "dev-id-2" ],
"GeneralRules": [
{
"Endpoint": "*",
"Period": "5m",
"Limit": 1
}
]
}
For testing purposes I have it set to 1 call every 5 minutes for the entire API, but I can easily make the same call multiple times in a row with no issues.
Can anyone tell me what I'm doing wrong here?