Other 2xx codes
All HTTP status codes in ASP.NET Core
2xx Success
The request succeeded and there is no body.
In ASP.NET Core: Typical for PUT, PATCH and DELETE when nothing needs to be returned.
The StatusCodes constant, HttpStatusCode enum name, reason phrase, class, and how EnsureSuccessStatusCode() and the standard resilience handler treat 204.
| Constant | StatusCodes.Status204NoContent |
|---|---|
| HttpStatusCode | HttpStatusCode.NoContent |
| Reason phrase | Kestrel sends No Content |
| Class | 2xx, success |
| IsSuccessStatusCode | true |
| EnsureSuccessStatusCode() | does not throw |
| Standard resilience handler | does not retry it |
TypedResults.NoContent()
Results.StatusCode(StatusCodes.Status204NoContent)NoContent()
StatusCode(StatusCodes.Status204NoContent)Checked on Kestrel: Results.NoContent() returns 204.
Setup
[HttpGet("null")]
public Thing? GetNull() => null;Request
GET /api/things/null HTTP/1.1Response (recorded)
HTTP/1.1 204 No ContentMVC's HttpNoContentOutputFormatter turns a null result into 204 No Content with an empty body. Clients that expect JSON (or 404 for a missing item) are surprised by it.
Fix: Return NotFound() when the item does not exist, or remove the formatter: options.OutputFormatters.RemoveType<HttpNoContentOutputFormatter>().
Setup
app.MapGet("/null", () => (Payload?)null);Request
GET /null HTTP/1.1Response (recorded)
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
nullMinimal APIs serialize null as the JSON literal null with 200 OK. Controllers behave differently and send 204 (below). Return TypedResults.NotFound() or NoContent() explicitly if that is what you mean.
Every response on this page was recorded from ASP.NET Core 10.0.12 on Kestrel in the Production environment; the HttpClient rows come from .NET 10.0.12 and Microsoft.Extensions.Http.Resilience 10.10.0.
All HTTP status codes in ASP.NET Core