dotnet / dotnet/aspnetcore

MapFallback catch all requests to API controller when ConsumeAttribute added

Open
#41,060 18 comments 2 reactions 0 assignees View on GitHub
area-mvc bug feature-routing
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Hello.
In .net 6 behavior of MapFallback broke when ConsumesAttribute was added. MapFallback catch all requests to API controller.
In .net 6 index.html file always returns on requests to API controller but if I remove endpoints.MapFallbackToFile or delete ConsumesAttribute filter then everything works as I expected.
**In .net 5 the example works correctly.**

ConsumesAttribute was added for the correct generation of swagger.json by Swashbuckle in order not to add it to every action or controller.

### Expected Behavior

Requests to controllers must not be catched by MapFallback.

### Steps To Reproduce

```c#
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers(options => options.Filters.Add(new ConsumesAttribute("application/json")));
}
public void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
}
}
```

### Exceptions (if any)

_No response_

### .NET Version

6.0.200

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.