Other 4xx codes
All HTTP status codes in ASP.NET Core
4xx Client error
The server cannot produce a response in any format the client listed in its Accept header.
In ASP.NET Core: ASP.NET Core ignores Accept and returns JSON unless you set ReturnHttpNotAcceptable = true.
The StatusCodes constant, HttpStatusCode enum name, reason phrase, class, and how EnsureSuccessStatusCode() and the standard resilience handler treat 406.
| Constant | StatusCodes.Status406NotAcceptable |
|---|---|
| HttpStatusCode | HttpStatusCode.NotAcceptable |
| Reason phrase | Kestrel sends Not Acceptable |
| Class | 4xx, client error |
| IsSuccessStatusCode | false |
| EnsureSuccessStatusCode() | throws HttpRequestException: Response status code does not indicate success: 406 (Not Acceptable). |
| Standard resilience handler | does not retry it |
Results.StatusCode(StatusCodes.Status406NotAcceptable)
Results.Problem(statusCode: StatusCodes.Status406NotAcceptable, detail: "...")StatusCode(StatusCodes.Status406NotAcceptable)
Problem(statusCode: StatusCodes.Status406NotAcceptable, detail: "...")What Results.Problem(statusCode: 406) sends (with AddProblemDetails()), as application/problem+json:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.7",
"title": "Not Acceptable",
"status": 406,
"traceId": "0HNA1B2C3D4E5:00000001"
}A controller's Problem(statusCode: 406) sends the same body.
A bare StatusCode(406) in an [ApiController] also gets a ProblemDetails body automatically; Results.StatusCode(406) in a minimal API sends an empty body unless you add UseStatusCodePages().
Setup
builder.Services.AddControllers(o => o.ReturnHttpNotAcceptable = true);Request
GET /api/things/one HTTP/1.1
Accept: application/xmlResponse (recorded)
HTTP/1.1 406 Not AcceptableWith ReturnHttpNotAcceptable, a request for a format you cannot produce gets 406.
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.
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