Other 2xx codes
All HTTP status codes in ASP.NET Core
2xx Success
The request succeeded. For GET the body is the resource; for POST, the result of the action.
In ASP.NET Core: The default for a handler that returns a value.
The StatusCodes constant, HttpStatusCode enum name, reason phrase, class, and how EnsureSuccessStatusCode() and the standard resilience handler treat 200.
| Constant | StatusCodes.Status200OK |
|---|---|
| HttpStatusCode | HttpStatusCode.OK |
| Reason phrase | Kestrel sends OK |
| Class | 2xx, success |
| IsSuccessStatusCode | true |
| EnsureSuccessStatusCode() | does not throw |
| Standard resilience handler | does not retry it |
TypedResults.Ok()
TypedResults.Ok<TValue>(value)
TypedResults.ServerSentEvents(values)
TypedResults.ServerSentEvents<T>(values)
Results.StatusCode(StatusCodes.Status200OK)
Results.Problem(statusCode: StatusCodes.Status200OK, detail: "...")Ok()
Ok(value)
StatusCode(StatusCodes.Status200OK)
Problem(statusCode: StatusCodes.Status200OK, detail: "...")What Results.Problem(statusCode: 200) sends (with AddProblemDetails()), as application/problem+json:
{
"title": "OK",
"status": 200,
"traceId": "0HNA1B2C3D4E5:00000001"
}A controller's Problem(statusCode: 200) sends a different body, because MVC only fills type and title for codes in ApiBehaviorOptions.ClientErrorMapping:
{
"status": 200,
"traceId": "0HNA1B2C3D4E5:00000001"
}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.
Setup
builder.Services.AddControllers();Request
GET /api/things/one HTTP/1.1
Accept: application/xmlResponse (recorded)
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"name": "a"
}No XML formatter, and ASP.NET Core falls back to JSON with 200 instead of refusing.
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>().
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