ApiVersionMatchPolicy invalidates catch-all endpoint incorrectly
- 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
### Describe the bug
I have two endpoint candidates for the same route `/a/b`:
- One with the complete route explicitly stated (let's call this the "exact match")
- One catch-all `/{**blah}` (let's call this "fallback")
Both have the `[ApiVersionNeutral]` attribute.
Based only on this, a request to `/a/b` should call the exact match endpoint.
However, I have my own `IActionConstraint` that discriminates based on a request header. Its `Order` is `0` (the default, as far as I understand).
The exact match endpoint is annotated with this attribute, only allowing certain request header values.
Now, if I send a request *without* a correct request header value, I expect this request to end up in the fallback endpoint, as the exact endpoint does not match because of the `IActionConstraint`.
Unfortunately, I get a `404` back. After some debugging, I learned that the following happens:
1. Both endpoints are valid candidates for routing.
2. The `ApiVersionMatcherPolicy` is executed first. It looks at both candidates and finds no problem with either. However, because the fallback endpoint has a higher score (`1` vs `0` for the exact match), it is marked as invalid.
3. The `ActionConstraintMatcherPolicy` should now check both candidates whether they can accept the request. The exact match is discarded because the header value is incorrect (as expected). But because the fallback endpoint has been marked as invalid, it is not taken into consideration now!
4. No valid endpoint has been found, so it returns a `404`.
I think the `ApiVersionMatcherPolicy` should only mark all endpoints as valid that match the request, not only the "best match".
### Expected Behavior
See above: I expect the request to end up at the fallback endpoint.
### Steps To Reproduce
See above
### Exceptions (if any)
_No response_
### .NET Version
`8.0.403`
### Anything else?
```
.NET SDK:
Version: 8.0.403
Commit: c64aa40a71
Workload version: 8.0.400-manifests.18f19b92
MSBuild version: 17.11.9+a69bbaaf5
Runtime Environment:
OS Name: manjaro
OS Version:
OS Platform: Linux
RID: linux-x64
Base Path: /usr/share/dotnet/sdk/8.0.403/
.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.
Host:
Version: 8.0.10
Architecture: x64
Commit: 81cabf2857
.NET SDKs installed:
8.0.403 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
DOTNET_ROOT [/usr/share/dotnet]
global.json file:
Not found
```
Contributor guide
Assessment
This issue has not been assessed yet.