[Produces] attribute should optionally participate in routing.
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
I've asked [the questions in discussions](https://github.com/dotnet/aspnetcore/discussions/63918), but I'm not satisfied with how it's currently implemented.
The most concerning is the fact that action gets executed even if `Accept` header does not match the value of `[Produces]` attribute.
### Describe the solution you'd like
[Produces] attribute should probably implement action/endpoint filter as well, so it short circuits the execution and immdeiately replys with 406.
To avoid breaking change, I'd make the default behavior of the new filter as pass through.
There should be some additional property to enable filtering. Something like `bool CheckAcceptedTypeBeforeActionExecution`:
```
[Produces("text/csv", CheckAcceptedTypeBeforeActionExecution = true)]
```
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.