Repository navigation
Conversation
Author
|
Done, thanks! |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The UseWhen explanation incorrectly says it does not create a separate branch; it should describe a branch that rejoins the main pipeline when it calls next.
1 open issue
What changed in this PR
This PR updates the HTTP handlers migration guide to explain conditional middleware behavior, addressing #10520 in the article’s current location.
Changes:
- Explains that matching
MapWhenrequests don't continue through downstream middleware on the main pipeline. - Introduces
UseWhenas the alternative for continuing through the pipeline and links to the middleware branching guide.
| File | Description |
|---|---|
aspnetcore/migration/fx-to-core/areas/http-handlers.md |
Adds the MapWhen versus UseWhen explanation and supporting references. |
Review effort: Balanced
|
|
||
| Middleware added to the pipeline before the branch will be invoked on all requests; the branch will have no impact on them. | ||
|
|
||
| <xref:Microsoft.AspNetCore.Builder.MapWhenExtensions.MapWhen*> creates a separate branch. When the predicate returns `true`, only the middleware added to the branch runs, and middleware registered on the main pipeline after `MapWhen` doesn't run for that request. To run middleware conditionally and then continue with the rest of the pipeline, use <xref:Microsoft.AspNetCore.Builder.UseWhenExtensions.UseWhen*> instead. `UseWhen` doesn't create a separate branch, so middleware registered after it runs whether the predicate returns `true` or `false`, unless the conditional middleware short-circuits the request. For more information, see [Branch the middleware pipeline](../../../fundamentals/middleware/index.md#branch-the-middleware-pipeline). |
Collaborator
There was a problem hiding this comment.
The suggested change LGTM ☝️.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #10520
Adds a note to the
MapWhensection of Migrate HTTP handlers to ASP.NET Core middleware:MapWhencreates a separate branch, so middleware registered after it on the main pipeline doesn't run for matching requests, whileUseWhenrejoins the main pipeline. The wording follows the explanation in the issue comments and links to Branch the middleware pipeline.The issue pointed at
migration/http-modules.md, which no longer has this section; theMapWhenguidance now lives inmigration/fx-to-core/areas/http-handlers.md.Internal previews
Build report