IpRateLimiter.AspNetCore.AltairCA
1.0.0
See the version list below for details.
dotnet add package IpRateLimiter.AspNetCore.AltairCA --version 1.0.0
NuGet\Install-Package IpRateLimiter.AspNetCore.AltairCA -Version 1.0.0
<PackageReference Include="IpRateLimiter.AspNetCore.AltairCA" Version="1.0.0" />
paket add IpRateLimiter.AspNetCore.AltairCA --version 1.0.0
#r "nuget: IpRateLimiter.AspNetCore.AltairCA, 1.0.0"
// Install IpRateLimiter.AspNetCore.AltairCA as a Cake Addin #addin nuget:?package=IpRateLimiter.AspNetCore.AltairCA&version=1.0.0 // Install IpRateLimiter.AspNetCore.AltairCA as a Cake Tool #tool nuget:?package=IpRateLimiter.AspNetCore.AltairCA&version=1.0.0
IpRateLimiter.AspNetCore.AltairCA
IpRateLimiter.AspNetCore.AltairCA is an request limiting solution by looking at the client ip address.
Inspired by AspNetCoreRateLimit
repo link
IpRateLimiter.AspNetCore.AltairCA
targets netstandard2.0
. The package has following dependencies
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="1.1.3" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
setup
NuGet install:
Install-Package IpRateLimiter.AspNetCore.AltairCA
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddMemoryCache();
services.AddHttpContextAccessor();
services.AddScoped<IIpRateLimitStorageProvider, MemoryCacheProvider>();
services.AddIpRateLimiter(options =>
{
options.GlobalRateLimit = 10;
options.GlobalSpan = TimeSpan.FromMinutes(30);
options.ExcludeList = new List<string>
{
"127.0.0.1", "192.168.0.0/24"
};
});
}
Default options for IpRateLimit
public class IpRateLimitOptions
{
public string RealIpHeader { get; set; }
public List<string> ExcludeList { get; set; }
public int GlobalRateLimit { get; set; } = 1000;
public TimeSpan GlobalSpan { get; set; } = TimeSpan.FromMinutes(30);
public int StatusCode { get; set; } = 429;
public object LimitReachedResponse = new {detail = "Quota exceeded. Maximum allowed: {0} per {1}. Please try again in {2} second(s)." };
public string CachePrefix { get; set; } = "AltairCA";
}
Using it in a controller
[Route("api/[controller]")]
[ApiController]
[IpRateLimitHttp]
public class ValuesController : ControllerBase
{
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}
[IpRateLimitHttp(10*60,2,"group1" )]
// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}
[IpRateLimitHttp(10*60,2,"group1" )]
[HttpPost]
public void Post([FromBody] string value)
{
}
}
You can apply the filter attribute at the top of the controller class. It will apply the rule for all of the endpoints that defined in the controller or you can put the attribute at the endpoint level. If you put the attribute at the class level and the endpoint level it will work as a AND
operator.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Mvc.Abstractions (>= 1.1.3)
- Microsoft.AspNetCore.Mvc.Core (>= 1.1.3)
- Microsoft.Extensions.Caching.Abstractions (>= 1.1.0)
- Microsoft.Extensions.Configuration (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection (>= 2.2.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 2.2.0)
- Newtonsoft.Json (>= 12.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.