dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.55k stars 10.05k forks source link

[.NET 8][MVC] Created() method on IActionResult returns 204NoContent StatusCode #58949

Open jaceks2106 opened 1 week ago

jaceks2106 commented 1 week ago

Is there an existing issue for this?

Describe the bug

.NET 8. When controller endpoint has return type IActionResult and return object is made by parameterless Created() method, response status code is 204. The workaround is following:

return Created((string)null, null);

Expected Behavior

I do not mean, that when there is no content in the response, then NoContent should not be returned, but when I explicitly want to return 201, I would expect 201, otherwise it's a breaking change for the contract of our WebAPI.

Steps To Reproduce

[HttpPost("TestB")]
public IActionResult Post()
{
    return Created();
}

Exceptions (if any)

No response

.NET Version

8.0.400

Anything else?

No response

oussamatecnique commented 1 week ago

I checked the issue, correct Created() return 204, this seems to be fixed in dotnet9. in this commit: https://github.com/dotnet/aspnetcore/commit/2bcfbd783a1e421840b2a638ff193ebb527c184e for dotnet8 I am not sure if an open PR exist. If not I can contribute one