-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35583 from dotnet/main
- Loading branch information
Showing
44 changed files
with
723 additions
and
629 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
docs/core/compatibility/aspnet-core/8.0/addratelimiter-requirement.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
title: "Breaking change: Rate-limiting middleware requires AddRateLimiter" | ||
description: Learn about the breaking change in ASP.NET Core 8.0 where rate-limiting middleware now requires AddRateLimiter to be called on app startup. | ||
ms.date: 05/30/2023 | ||
--- | ||
# Rate-limiting middleware requires AddRateLimiter | ||
|
||
ASP.NET Core rate-limiting middleware has been updated with extra functionality. The middleware now requires services registered with <xref:Microsoft.AspNetCore.Builder.RateLimiterServiceCollectionExtensions.AddRateLimiter%2A>. | ||
|
||
## Version introduced | ||
|
||
ASP.NET Core 8.0 Preview 5 | ||
|
||
## Previous behavior | ||
|
||
Previously, rate limiting could be used without <xref:Microsoft.AspNetCore.Builder.RateLimiterServiceCollectionExtensions.AddRateLimiter%2A>. For example, the middleware could be configured by calling `Configure<RateLimiterOptions>(o => { })`: | ||
|
||
```csharp | ||
var builder = WebApplication.CreateBuilder(args); | ||
builder.Services.Configure<RateLimiterOptions>(o => o | ||
.AddFixedWindowLimiter(policyName: "fixed", options => | ||
{ | ||
// configuration | ||
})); | ||
|
||
var app = builder.Build(); | ||
app.UseRateLimiter(); | ||
app.MapGet("/", () => Results.Ok($"Hello world")).RequireRateLimiting("fixed"); | ||
app.Run(); | ||
``` | ||
|
||
## New behavior | ||
|
||
If <xref:Microsoft.AspNetCore.Builder.RateLimiterServiceCollectionExtensions.AddRateLimiter%2A> is not called on app startup, ASP.NET Core throws an informative error: | ||
|
||
> Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddRateLimiter' in the application startup code. | ||
## Type of breaking change | ||
|
||
This change is a [behavioral change](../../categories.md#behavioral-change). | ||
|
||
## Reason for change | ||
|
||
Rate-limiting middleware requires services that are only registered by calling <xref:Microsoft.AspNetCore.Builder.RateLimiterServiceCollectionExtensions.AddRateLimiter%2A>. | ||
|
||
## Recommended action | ||
|
||
Ensure that <xref:Microsoft.AspNetCore.Builder.RateLimiterApplicationBuilderExtensions.UseRateLimiter%2A> is called at application startup. | ||
|
||
For example, update `Configure<RateLimiterOptions>(o => { })` to use <xref:Microsoft.AspNetCore.Builder.RateLimiterApplicationBuilderExtensions.UseRateLimiter%2A>: | ||
|
||
```csharp | ||
var builder = WebApplication.CreateBuilder(args); | ||
builder.Services.AddRateLimiter(o => o | ||
.AddFixedWindowLimiter(policyName: "fixed", options => | ||
{ | ||
// configuration | ||
})); | ||
|
||
var app = builder.Build(); | ||
app.UseRateLimiter(); | ||
app.MapGet("/", () => Results.Ok($"Hello world")).RequireRateLimiting("fixed"); | ||
app.Run(); | ||
``` | ||
|
||
## Affected APIs | ||
|
||
- <xref:Microsoft.AspNetCore.Builder.RateLimiterApplicationBuilderExtensions.UseRateLimiter%2A?displayProperty=fullName> |
Oops, something went wrong.