RateLimit 1.0.1
.NET Framework 4.5
dotnet add package RateLimit --version 1.0.1
NuGet\Install-Package RateLimit -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RateLimit" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RateLimit --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RateLimit, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install RateLimit as a Cake Addin
#addin nuget:?package=RateLimit&version=1.0.1
// Install RateLimit as a Cake Tool
#tool nuget:?package=RateLimit&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Author: Khoi Tran
Package: RateLimit
The lightweight .NET Framework
package provides a middleware service to protect your application by limiting the request rate.
If an IpAddress
contains the number of requests which cross over the MaxRequestPerPeriod
, it will be blocked by returning a TooManyRequest(429)
(config by BlockMessage
) within the blocking time (config by BlockTimeSecond
)
Installation
nuget install RateLimit
Usage
Global.asax.cs
: regis global default RateLimit configuration
/// ...
using RateLimit; // use RateLimit package
using RateLimit.Configs; // use RateLimit package configuration
namespace WebMVC
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
/// ...
/*
* Default configuration using HttpRuntime (Memory cache and Redis are support too)
* Expand the RedisConfig, MemoryConfig or HttpRuntimeConfig to see more
*/
RateLimitContext.RegisterConfig();
}
}
}
ExampleController.cs
: config RateLimitAttribute forGetReport
action
using Newtonsoft.Json;
using System.Web.Mvc;
using RateLimit; // use RateLimit package
namespace WebMVC.Controllers
{
public class ExampleController : Controller
{
/* Config for every request come to this action */
[RateLimit(PeriodTime = 10, MaxRequestPerPeriod = 1, BlockTime = 10, BlockMessage = "You are making too many request")]
public string GetReport(string param1)
{
return param1;
}
}
}
Advance
Global.asax.cs
: custom regis global default RateLimit configuration
/// ...
using RateLimit; // use RateLimit package
using RateLimit.Configs; // use RateLimit package configuration
namespace WebMVC
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
/// ...
/// ...
/* Full global config */
RateLimitContext.RegisterConfig(
new RateLimitConfig(
/* Global config for request rate */
rateConfig: new RequestRateConfig
{
BlockMessage = "You are making too many request, please try after 60 second",
BlockTime = 60,
CookieName = "ASP.NET_SessionId",
MaxRequestPerPeriod = 1,
PeriodTime = 10
},
/* Cache config, default is new HttpRuntimeConfig() */
cacheConfig: new RedisConfig()
{
CacheTimeSecond = 3600,
ConnectTimeoutSecond = 5,
DatabaseIndex = 0,
EndPoints = "localhost:6379"
}
)
);
}
}
}
ExampleController.cs
: Use default global rate configuration
/// ...
using RateLimit; // use RateLimit package
namespace WebMVC.Controllers
{
public class ExampleController : Controller
{
/* Use default global rate configuration */
[RateLimit]
public string GetReport(string param1)
{
return param1;
}
}
}
Product | Versions |
---|---|
.NET Framework | net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 net481 |
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.5
- Microsoft.AspNet.Mvc (>= 5.0.2)
- Newtonsoft.Json (>= 9.0.1)
- StackExchange.Redis (>= 1.2.6)
- System.Runtime.Caching (>= 4.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Add static .dll