RateLimiter.IISModule
1.0.1
See the version list below for details.
dotnet add package RateLimiter.IISModule --version 1.0.1
NuGet\Install-Package RateLimiter.IISModule -Version 1.0.1
<PackageReference Include="RateLimiter.IISModule" Version="1.0.1" />
<PackageVersion Include="RateLimiter.IISModule" Version="1.0.1" />
<PackageReference Include="RateLimiter.IISModule" />
paket add RateLimiter.IISModule --version 1.0.1
#r "nuget: RateLimiter.IISModule, 1.0.1"
#:package RateLimiter.IISModule@1.0.1
#addin nuget:?package=RateLimiter.IISModule&version=1.0.1
#tool nuget:?package=RateLimiter.IISModule&version=1.0.1
IIS Rate Limiter Module
A custom IIS HTTP Module for subsystem-wise and API-wise rate limiting. Perfect for APIs that use custom authentication headers to identify clients/subsystems.
Features
- Per-endpoint rate limiting - Different limits for different URLs
- URL pattern matching - Wildcards support (
*for segment,**for any path) - HTTP method filtering - Different limits for GET vs POST
- Client identification - IP address, API keys, custom headers
- Request data analysis - Include query parameters and headers in rate limit key
- JSON body parsing - Extract fields from request body for rate limiting
- Sliding window algorithm - Smooth rate limiting without sharp resets
- Configurable via JSON - Easy configuration without code changes
Installation
1. Build the Module
cd RateLimiter.IISModule
dotnet build -c Release
2. Deploy to Your Web Application
Copy the built DLL to your application's bin folder:
copy .\bin\Release\net48\RateLimiter.IISModule.dll C:\inetpub\wwwroot\YourApp\bin\
copy .\bin\Release\net48\Newtonsoft.Json.dll C:\inetpub\wwwroot\YourApp\bin\
3. Register the Module in web.config
Add to your application's web.config:
<configuration>
<system.webServer>
<modules>
<add name="RateLimitingModule"
type="RateLimiter.IISModule.RateLimitingModule, RateLimiter.IISModule"
preCondition="managedHandler" />
</modules>
</system.webServer>
</configuration>
4. Configure Rate Limits
Create App_Data\ratelimit.config.json in your web application:
{
"includeUrlInKey": true,
"includeMethodInKey": true,
"clientIdHeader": "X-API-Key",
"defaultRule": {
"name": "Default",
"maxRequests": 100,
"windowSeconds": 60
},
"rules": [
{
"name": "Login",
"urlPattern": "/api/auth/login",
"methods": ["POST"],
"maxRequests": 5,
"windowSeconds": 60,
"priority": 100
}
]
}
Configuration Options
Global Settings
| Setting | Type | Description |
|---|---|---|
includeUrlInKey |
bool | Include URL path in rate limit key (per-endpoint limiting) |
includeMethodInKey |
bool | Include HTTP method in rate limit key |
clientIdHeader |
string | Custom header for client identification (e.g., "X-API-Key") |
queryParametersToInclude |
string[] | Query parameters to include in rate limit key |
headersToInclude |
string[] | Headers to include in rate limit key |
whitelistedIPs |
string[] | IPs that bypass rate limiting |
excludedPaths |
string[] | Paths excluded from rate limiting |
Rate Limit Rules
| Setting | Type | Description |
|---|---|---|
name |
string | Rule name for identification |
urlPattern |
string | URL pattern (* = segment, ** = any path) |
methods |
string[] | HTTP methods (empty = all) |
maxRequests |
int | Max requests allowed in window |
windowSeconds |
int | Time window in seconds |
priority |
int | Higher priority rules checked first |
enabled |
bool | Enable/disable rule |
URL Pattern Examples
| Pattern | Matches |
|---|---|
/api/users |
Exact match |
/api/users/* |
/api/users/123, /api/users/abc |
/api/** |
Any path under /api/ |
/api/*/profile |
/api/123/profile, /api/abc/profile |
Response Headers
When rate limited, the module returns:
- Status Code:
429 Too Many Requests - Retry-After: Seconds until the window resets
- X-RateLimit-Limit: Maximum requests allowed
- X-RateLimit-Window: Time window duration
Advanced Usage
Rate Limiting by Request Body Content
For advanced scenarios like rate limiting by user ID in the request body, you can extend the module to use RequestBodyAnalyzer:
// Extract fields from JSON body
var fields = RequestBodyAnalyzer.ExtractJsonFields(request, new[] { "userId", "action" });
// Include in rate limit key
foreach (var field in fields)
{
keyParts.Add($"{field.Key}={field.Value}");
}
Combining with IIS Dynamic IP Restrictions
For defense in depth, combine this module with IIS's built-in IP restrictions:
<security>
<dynamicIpSecurity denyAction="Forbidden">
<denyByConcurrentRequests enabled="true" maxConcurrentRequests="20" />
<denyByRequestRate enabled="true" maxRequests="100" requestIntervalInMilliseconds="1000" />
</dynamicIpSecurity>
</security>
Troubleshooting
Module Not Loading
- Ensure .NET Framework 4.8 is installed
- Check Application Pool is using .NET 4.0 CLR
- Verify DLLs are in the
binfolder
Rate Limits Not Applied
- Check the module is registered in
web.config - Verify
ratelimit.config.jsonis inApp_Datafolder - Check URL patterns match your endpoints
Performance Considerations
- The module uses in-memory storage (fast but not distributed)
- For web farm scenarios, consider Redis-based implementation
- Cleanup runs every minute to prevent memory leaks
License
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net45 is compatible. net451 is compatible. net452 is compatible. net46 is compatible. net461 is compatible. net462 is compatible. net463 was computed. net47 is compatible. net471 is compatible. net472 is compatible. net48 is compatible. net481 was computed. |
-
.NETFramework 4.5
- Newtonsoft.Json (>= 13.0.3)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.5.1
- Newtonsoft.Json (>= 13.0.3)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.5.2
- Newtonsoft.Json (>= 13.0.3)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.6
- Newtonsoft.Json (>= 13.0.3)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.6.1
- Newtonsoft.Json (>= 13.0.3)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.6.2
- Newtonsoft.Json (>= 13.0.3)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.7
- Newtonsoft.Json (>= 13.0.3)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.7.1
- Newtonsoft.Json (>= 13.0.3)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.7.2
- Newtonsoft.Json (>= 13.0.3)
- System.ValueTuple (>= 4.5.0)
-
.NETFramework 4.8
- Newtonsoft.Json (>= 13.0.3)
- System.ValueTuple (>= 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.