A rate limit library for ASP.NET Core.
$ dotnet add package FireflySoft.RateLimit.AspNetCoreFireflysoft.RateLimit is a rate limiting library based on .Net standard. Its core is simple and lightweight, and can flexibly meet the rate limiting needs of many scenarios.
The following code calls the rate-limit middleware from Startup.Configure:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddRateLimit(new InProcessFixedWindowAlgorithm(
new[] {
new FixedWindowRule()
{
ExtractTarget = context =>
{
return (context as HttpContext).Request.Path.Value;
},
CheckRuleMatching = context =>
{
return true;
},
Name="default limit rule",
LimitNumber=30,
StatWindow=TimeSpan.FromSeconds(1)
}
})
);
...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.UseRateLimit();
...
}