-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Implicit call to UseRouting() in WebApplicationBuilder creates ordering issue with pipeline rerunning middleware, e.g. UseExceptionHandler #34146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for contacting us. We're moving this issue to the |
Had a chat with @halter73 and I think we'll try to add an analyzer that will warn when an incorrect configuration is detected (i.e. UseExceptionHandler configured with a path called after UseRouting or called with no explicit UseRouting). We also discussed two other options:
|
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
2 similar comments
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
@BrennanConroy I moved this out of API review since it doesn't sound like any additional work has been done since we looked at it last week? If that's not the case and this API is actually ready, please bring this back up. FYI @halter73 / @javiercn / @davidfowl |
API propsal:
Background and Motivation
To support middlewares that modify routes in Minimal APIs where UseRouting is called implicitly, we want to allow UseRouting to be called more than once in the app pipeline. E.g.
To support this, we need to make a change to
UseRouting()
since it overrides theEndpointRouteBuilder
in theProperties
bag of the builder: https://github.com/dotnet/aspnetcore/blob/main/src/Http/Routing/src/Builder/EndpointRoutingApplicationBuilderExtensions.cs#L48. Given this would be a breaking behaviour change, we want to add an overload that would use existingEndpointRouteBuilder
if one can be found.Proposed API
namespace Microsoft.AspNetCore.Builder { public static class EndpointRoutingApplicationBuilderExtensions { + public static IApplicationBuilder UseRouting(this IApplicationBuilder builder, bool overrideEndpointRouteBuilder); }
Usage Examples
The usage pattern we expect is in middleware extensions:
Alternative Designs
#30549
Risks
Is this the best way to allow recalculation of the endpoint?
Original issue:
WebApplicationBuilder
implicitly callsUseRouting()
early on in the pipeline which causes issues for middleware added by the application that re-runs the pipeline after changing the path, includingUseExceptionHandler
. We likely need to revisit this behavior and potentially decide whether we also implicitly add middleware likeUseDeveloperExceptionPage
andUseExceptionHandler
fromWebApplicationBuilder
to resolve this kinds of ordering issues.Consider the following app:
Requests for "/" and "/error" directly from the browser work fine, but attempting to request "/throw" results in the following exception and a 500 result being returned:
Proposal:
We add
UseRouting()
in the error branch. This requires a new overload toUseRouting
since the current one replaces theIEndpointRouteBuilder
here:Current proposal: https://github.com/dotnet/aspnetcore/compare/johluo/diagnostic-option3?expand=1
@davidfowl
The text was updated successfully, but these errors were encountered: