Search code examples
c#asp.net-coreroutesodata

How do I configure OData to use a POST with /$query on an endpoint configured with ODataAttributeRouting? I'm getting a 404


This is a follow-up to OData AspNetCore support for long URLs useing $query is not working.

OData 8.0.4

In startup, I have app.UseODataQueryRequest() My Controller looks like

[ODataAttributeRouting]
public class ODataQueryController : Controller
{
    [HttpGet] // not needed, it turns out
    [EnableQuery]
    [Route("Thing")]
    public IActionResult GetThings()
    {
        return Ok(ApplicationContext.Things);
    }
}

and my POST looks like

POST http://localhost:8080/api/odata/Thing/$query

Request Body: $select=Column
Content-Type: text/plain

and I get a 404


Solution

  • Placing app.UseODataQueryRequest() before app.UseRouting() resolved this issue for me

    Startup.cs:

    ...
    app.UseODataQueryRequest();
    ...
    app.UseRouting();
    ...