aspnet / AspNetWebStack

ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x (not ASP.NET Core)
Other
858 stars 354 forks source link

ASP.NET Web API versioning Migrate from QueryStringApiVersionReader to UrlSegmentApiVersionReader #412

Closed barbosatekBU closed 1 year ago

barbosatekBU commented 1 year ago

I'm currently looking into migrate an API versioning mechanism from using query parameter to use url fragments. However, I need to maintain backwards compatibility, so if the caller specifies the version on the query, it fulfills the new url segment on the route. My routes will go from:

[Route("articles")] to [Route("v{version:apiVersion}/articles")]

However, it seems when passing the api version as query parameter, the routing won't find the route (because the version is missing) and it will return 404.

Is there a way to support both, UrlSegmentApiVersionReader and QueryStringApiVersionReader at the same time?

Thanks