Method AddClientFixedWindowLimiter
AddClientFixedWindowLimiter(RateLimiterOptions, string, int, TimeSpan)
Adds a rate limiting policy that allows each client address a fixed number of requests per window. Apply it to endpoints with RequireRateLimiting<TBuilder>(TBuilder, string).
Declaration
public static RateLimiterOptions AddClientFixedWindowLimiter(this RateLimiterOptions options, string policyName, int permitLimit, TimeSpan window)
Parameters
| Type | Name | Description |
|---|---|---|
| RateLimiterOptions | options | The rate limiter options. |
| string | policyName | The name of the policy. |
| int | permitLimit | The number of requests each client can make in each window (see PermitLimit). |
| TimeSpan | window | The length of a window (see Window). |
Returns
| Type | Description |
|---|---|
| RateLimiterOptions |
Remarks
See ClientRateLimitOptions for how clients are identified and which clients are exempt. The configurations added with
ConfigureClientLimits(RateLimiterOptions, Action<ClientRateLimitOptions>) before this call run before configure.
If OnRejected is not set, this also sets the rejection response with SetApiRejectionResponse(RateLimiterOptions, string?).
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
| FormatException | An entry in ExemptNetworks is not a valid address or network. |
AddClientFixedWindowLimiter(RateLimiterOptions, string, Action<ClientRateLimitOptions>)
Adds a rate limiting policy that allows each client address a fixed number of requests per window. Apply it to endpoints with RequireRateLimiting<TBuilder>(TBuilder, string).
Declaration
public static RateLimiterOptions AddClientFixedWindowLimiter(this RateLimiterOptions options, string policyName, Action<ClientRateLimitOptions> configure)
Parameters
| Type | Name | Description |
|---|---|---|
| RateLimiterOptions | options | The rate limiter options. |
| string | policyName | The name of the policy. |
| Action<ClientRateLimitOptions> | configure | An action to configure the limit. PermitLimit must be set. |
Returns
| Type | Description |
|---|---|
| RateLimiterOptions |
Remarks
See ClientRateLimitOptions for how clients are identified and which clients are exempt. The configurations added with
ConfigureClientLimits(RateLimiterOptions, Action<ClientRateLimitOptions>) before this call run before configure.
If OnRejected is not set, this also sets the rejection response with SetApiRejectionResponse(RateLimiterOptions, string?).
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | PermitLimit was not set. |
| FormatException | An entry in ExemptNetworks is not a valid address or network. |