dotnet / dotnet/AspNetCore.Docs

Is it possible to add a rate limiter policy using chained limiters?

Open
#36,851 3 comments 0 reactions 1 assignee Claimed by @wadepickett View on GitHub
ai-triage-action-plan aspnet-core/svc performance/subsvc Source - Docs.ms
Dominant language
C#
Stars
13.1k
Forks
24.6k
Avg merge
1d 2h
Merged PRs (30d)
109

Description

### Description

Currently, the [rate limiting documentation](https://learn.microsoft.com/en-us/aspnet/core/performance/rate-limit?view=aspnetcore-10.0#create-chained-limiters) shows a single example of creating chained limiters and **applying them at a global level**. But is it possible to do the same when adding a rate limiting **policy**?

I also found [this discussion](https://github.com/dotnet/aspnetcore/discussions/54051), but again, there does not seem to be an example of creating a policy (non-global) that uses chained limiters.

For example, given:

```
Microsoft.AspNetCore.RateLimiting.RateLimiterOptions options;

var limiters_array = new RateLimiter[ 2 ];

// limiters_array populated here (code omitted for brevity)

/*
The following will NOT work as the .AddPolicy method expects a
second argument of: Func>
*/
options.AddPolicy( "chained", RateLimiter.CreateChained( limiters_array) );
```

There does not seem to be an overload (or clear) way to create a policy that incorporates chained limiters.

I have not (yet) come across anything in the documentation that explicitly states something such as:

"_chained limiters are only available at a global level_"

but if that IS true, it should be added to the documentation.

If I missed something in the documentation, I apologize in advance, but do request a link to the relevant method or page that illustrates how to create a **policy** that uses chained limiters.

Thanks in advance.

### Page URL

https://learn.microsoft.com/en-us/aspnet/core/performance/rate-limit-samples?view=aspnetcore-10.0&source=recommendations

### Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/performance/rate-limit-samples.md

### Document ID

d96ee509-2576-279e-29b3-89fbe44b0a28

### Platform Id

05af3602-fe02-0ab6-50c5-1058509c4fd9

### Article author

@wadepickett

### Metadata

* ID: d96ee509-2576-279e-29b3-89fbe44b0a28
* PlatformId: 05af3602-fe02-0ab6-50c5-1058509c4fd9
* Service: **aspnet-core**
* Sub-service: **performance**

[Related Issues](https://github.com/dotnet/AspNetCore.Docs/issues?q=is%3Aissue+is%3Aopen+d96ee509-2576-279e-29b3-89fbe44b0a28)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.