Skip to content
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

[Breaking change]: Static files, default document, and directory browsing middleware no longer no-op when an endpoint with a null RequestDelegate is active #488

Open
1 of 3 tasks
DamianEdwards opened this issue Jun 28, 2022 · 0 comments
Labels
7.0.0 Announcement Breaking change Documented The breaking change has been published to the .NET Core docs
Milestone

Comments

@DamianEdwards
Copy link
Member

Description

As detailed in dotnet/aspnetcore#42413, the file-serving middleware (DefaultFilesMiddleware, DirectoryBrowserMiddleware, and StaticFileMiddleware) have been updated to no longer no-op (i.e. defer to the next middleware in the pipeline) in the case that there is an active endpoint with a null request delegate.

PR that makes the change: dotnet/aspnetcore#42458

Version

.NET 7 Preview 7

Previous behavior

Previously, if the current request had an active endpoint, i.e. HttpContext.GetEndpoint() != null, the file-serving middleware would perform no action and simply delegate to the next middleware in the request pipeline.

New behavior

The file-serving middleware will now only perform no action if there is an active endpoint and its RequestDelegate property value is not null, i.e. HttpContext.GetEndpoint()?.RequestDelegate is not null.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
  • Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.
  • Behavioral change: Existing code and binaries may experience different run-time behavior.

Reason for change

This change will enable endpoints to be active in the request for the purposes of setting and sharing metadata with middleware that are endpoint-aware so that they can perform their intended function, while allowing other middleware (like the file-serving middleware) that would usually defer their behavior when an endpoint is active to also function.

For example, an endpoint with a null request delegate containing authorization metadata can be set as the active endpoint for a request, causing the AuthorizationMiddleware to enforce authorization requirements, which if satisfied would allow the StaticFileMiddleware to serve the requested files.

Recommended action

If you are relying on setting an active endpoint on the request to suppress the behavior of the file-serving middleware, ensure that the endpoint has a non-null value set for its RequestDelegate property.

Affected APIs

  • IApplicationBuilder.UseStaticFiles()
  • IApplicationBuilder.UseDefaultFiles()
  • IApplicationBuilder.UseDirectoryBrowser()
@aspnet aspnet locked and limited conversation to collaborators Jun 28, 2022
@DamianEdwards DamianEdwards added this to the 7.0.0 milestone Jul 13, 2022
@gewarren gewarren added the Documented The breaking change has been published to the .NET Core docs label Jul 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
7.0.0 Announcement Breaking change Documented The breaking change has been published to the .NET Core docs
Projects
None yet
Development

No branches or pull requests

2 participants