Closed
Description
The following example is reduced to its bare minimum. I have enabled URL-Path versioning for ASP.Net Web API according to the documentation in the Wiki:
this.config.MapHttpAttributeRoutes(new DefaultInlineConstraintResolver()
{
ConstraintMap =
{
["apiVersion"] = typeof(ApiVersionRouteConstraint)
}
});
this.config.AddApiVersioning();
Controller is defined like this:
[ApiVersion("1.0")]
[RoutePrefix("api/v{version:apiVersion}/resource")]
public class ResourceController : ApiController
{
[HttpGet]
[Route("{id:int}")]
public async Task<IHttpActionResult> Get([FromUri] int id)
{
return Ok();
}
[HttpDelete]
[Route("{id}")]
public async Task<IHttpActionResult> Delete(int id)
{
return Ok();
}
}
What happens is this:
- GET-request to
api/v1/resource/123
→ server responds with200 OK
. - GET-request to
api/v2/resource/123
→ server responds with400 Bad Request
, including the standard error response with error codeUnsupportedApiVersion
as described in the documentation wiki - GET-request to
api/v1/resource/asdf
→ server responds with400 Bad Request
, includingUnsupportedApiVersion
just as the previous example.
This seems wrong. The given URL would never match a route when GET-requested.
When i add the :int
constraint to the DELETE route or remove the route altogether, the GET-request to api/v1/resource/asdf
returns 404 Not Found
with an empty body as expected.