aspnet / Announcements

Subscribe to this repo to be notified about major changes in ASP.NET Core and Entity Framework Core
Other
1.66k stars 80 forks source link

[Breaking change]: Endpoints configured with 'MapFallbackToFile()' now only match 'HEAD' and 'GET' requests #495

Open MackinnonBuck opened 2 years ago

MackinnonBuck commented 2 years ago

Description

The ConsumesAttribute attribute allows controller actions to specify their supported content types. Starting in .NET 6, if a fallback file endpoint was configured, it could match routes that were discarded due to the request having a different content type than what was specified in an action's ConsumesAttribute. This was an undesirable change in behavior from .NET 5 that we are partially addressing in .NET 7 by making fallback file endpoints only match GET and HEAD requests.

Version

.NET 7 RC2

Previous behavior

Endpoints configured with StaticFilesEndpointRouteBuilderExtensions.MapFallbackToFile() may match requests made with any request method.

New behavior

Endpoints configured with StaticFilesEndpointRouteBuilderExtensions.MapFallbackToFile() will only match HEAD and GET requests.

Type of breaking change

Reason for change

This partially reverts larger breaking change accidentally introduced in .NET 6. Since it's highly unusual to expect a fallback file response when making a request with a method other than HEAD or GET, we anticipate the impact of this breaking change to be minimal.

Recommended action

If you want fallback file endpoints to match requests with methods other than HEAD or GET, you can specify additional HTTP request methods using WithMetadata(). For example:

endpoints.MapFallbackToFile("index.html")
    .WithMetadata(new HttpMethodMetadata(new[] { /* List supported methods here */ }));

Affected APIs

All overloads of StaticFilesEndpointRouteBuilderExtensions.MapFallbackToFile().