Skip to content

UmbracoApiController routing does not work if the route is the same for POST and GET requests #16434

Open
@lommijuho

Description

@lommijuho

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.2.2

Bug summary

When I upgraded from U10.5.1 to U13.2.2 I faced an issue that broke my UmbracoApiController routing. When I make a GET request to an endpoint that shares the route with a POST endpoint, the GET request returns a 404. If I use unique routes for each request method, everything seems to be working correctly.

Specifics

No response

Steps to reproduce

Create a fresh Umbraco project and add 2 controllers with the same route but different methods e.g.:

[ApiController]
[Route("api/")]
public class ProductManagementApiController : UmbracoApiController
{

    [HttpPost("test")]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [Consumes(MediaTypeNames.Application.Json)]
    public IActionResult CreateBrandProduct()
    {
        return Ok("OK POST");
    }

    [HttpGet("test")]
    [ProducesResponseType(StatusCodes.Status200OK)]
    public IActionResult GetAllBrandProducts()
    {

        return Ok("OK GET");
    }
}

Making a POST request works, but GET request request returns 404.
I was able to follow the issue and found out that ApiVersionMatcherPolicy.ApplyAsync() scores both of my endpoint candidates to a negative value and therefore makes both of them invalid. I'm not sure if this is the real issue but this could somehow be related to the problem. When removing ApiVersionMatcherPolicy from builder.Services, both endpoints worked correctly.

Expected result / actual result

I assume that in this situation both endpoints should work normally, because the request method is different.


This item has been added to our backlog AB#42384

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions