When we create something like this in NET 7:
app.MapPost("/test", SomeEndpoint.Test);
This is my SomeEndpoint.Test:
public static class SomeEndpoint
{
public static IResult Test(HttpContext httpContext)
{
var form = httpContext.Request.ReadFormAsync().Result;
return Results.Ok(form);
}
}
then anything works well. But I want to have it async, so now my SomeEndpoint.Test
looks as below:
public static class SomeEndpoint
{
public static async Task<IResult> Test(HttpContext httpContext)
{
var form = await httpContext.Request.ReadFormAsync();
return Results.Ok(form);
}
}
Boom. That's not working, I always get 200 OK response (even if I change my Results.Ok
to Results.BadRequest
). What am I doing wrong?