-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Open
Labels
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Defining the following ApiVersion causes endpoints that use this version to not be accessible (Error 404)
ApiVersion: "2.0-preview" (Major: 2, Minor: 0, status: "preview")
Expected Behavior
Endpoints for the ApiVersion are accessible, and actions can be called on it.
Steps To Reproduce
- Create a simple (default) ASP.NET Web Api project and enable Api versioning with URL segments (using the Asp.Versioning.Mvc Nuget package).
- Add the following Route attribute on the default controller:
[Route("v{version:apiVersion}/[controller]/[action]")]
- Add the following ApiVersion attributes on the default controller:
[ApiVersion("1.0")]
[ApiVersion("2.0-alpha")]
[ApiVersion("2.0-preview")]
- Run the Api
- Try to call a action of version "2.0-alpha" -> Works
- Try to call a action of version "2.0-preview" -> Doesn't work (error 404)
Exceptions (if any)
No response
.NET Version
8.0.403
Anything else?
After some early debugging, I came across the following method that seems to cause the issue: Microsoft.AspNetCore.Routing.RoutePatternMatcher.MatchComplexSegmentCore
More specifically the following portion:
int indexOfLiteral;
if (part.IsLiteral)
{
var literal = (RoutePatternLiteralPart)part;
indexOfLiteral = requestSegment.Slice(0, startIndex).LastIndexOf(
literal.Content,
StringComparison.OrdinalIgnoreCase);
}
Here it seems that the wrong index is calculated for the "v" literal that prefixes the version in the URL in the case of ApiVersion "2.0-preview".
It uses the index of the "v" in the word "preview" instead of the "v" at the start of the URL parameter "v2.0-preview".