Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiVersion status value causing routing issues (error 404) #59054

Open
1 task done
PascalWillems opened this issue Nov 19, 2024 · 0 comments
Open
1 task done

ApiVersion status value causing routing issues (error 404) #59054

PascalWillems opened this issue Nov 19, 2024 · 0 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Comments

@PascalWillems
Copy link

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

  1. Create a simple (default) ASP.NET Web Api project and enable Api versioning with URL segments (using the Asp.Versioning.Mvc Nuget package).
  2. Add the following Route attribute on the default controller: [Route("v{version:apiVersion}/[controller]/[action]")]
  3. Add the following ApiVersion attributes on the default controller:
  • [ApiVersion("1.0")]
  • [ApiVersion("2.0-alpha")]
  • [ApiVersion("2.0-preview")]
  1. Run the Api
  2. Try to call a action of version "2.0-alpha" -> Works
  3. 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".

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

No branches or pull requests

1 participant