I have a Web API project using .net core 2.2 (maybe there's the problem.)
The routes are awaiting OAuth authorization with OpenIdDict, but that works totally fine for me. I am trying a very simple approach:
The startup.cs just contains:
services.AddApiVersioning();
The API controller has three different routes for test purposes. Notice that the controller itself has no [Route()] or [ApiVersion()] annotations.
[HttpGet]
[Authorize]
[ApiVersion("2.0")]
[Route("api/v{version:apiVersion}/vt")]
public IActionResult GetVt20()
{
return Ok("2.0");
}
[HttpGet]
[Authorize]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/vt")]
public IActionResult GetVt10()
{
return Ok("1.0");
}
If I do an authorized request like
http://localhost:27713/api/v1.0/vt
.net core answers with a BadRequest:
{"error":{"code":"UnsupportedApiVersion","message":"The HTTP resource that matches the request URI 'http://localhost:27713/api/v1.0/vt' does not support the API version '1.0'.","innerError":null}}
What am I missing?
I had the same issue when migrating from 2.1 net core to 2.2 Just add to your controller class [ApiController] Attribute