I am trying to add versioning to my web api and after reading asp .net core documentation it seemed that IApplicationBuilder.UsePathBase could serve to this purpose. And, it really does but with a quirk. The api can still be accesed without adding the versioning path.
As an example, I use this to add an v1 path to my api:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHttpContextAccessor httpAccesor)
{
app.UsePathBase("/api/v1");
....
}
Now I am able to access my cars endpoint by using http://www...com/api/v1/cars or by using http://www...com/cars.
The cars controller routing is setup this way:
[Authorize]
[Route("/[controller]")]
[ApiController]
public class DriversController : ControllerBase
{
....
}
So, is this how it works? Is there any possibility to just allow paths with the corresponding versioning path?