Other 4xx codes
All HTTP status codes in ASP.NET Core
4xx Client error
A condition in the request headers (If-Match, If-Unmodified-Since) was false.
In ASP.NET Core: The standard answer for optimistic concurrency with ETags: the client's If-Match no longer matches.
The StatusCodes constant, HttpStatusCode enum name, reason phrase, class, and how EnsureSuccessStatusCode() and the standard resilience handler treat 412.
| Constant | StatusCodes.Status412PreconditionFailed |
|---|---|
| HttpStatusCode | HttpStatusCode.PreconditionFailed |
| Reason phrase | Kestrel sends Precondition Failed |
| Class | 4xx, client error |
| IsSuccessStatusCode | false |
| EnsureSuccessStatusCode() | throws HttpRequestException: Response status code does not indicate success: 412 (Precondition Failed). |
| Standard resilience handler | does not retry it |
Results.StatusCode(StatusCodes.Status412PreconditionFailed)
Results.Problem(statusCode: StatusCodes.Status412PreconditionFailed, detail: "...")StatusCode(StatusCodes.Status412PreconditionFailed)
Problem(statusCode: StatusCodes.Status412PreconditionFailed, detail: "...")What Results.Problem(statusCode: 412) sends (with AddProblemDetails()), as application/problem+json:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.13",
"title": "Precondition Failed",
"status": 412,
"traceId": "0HNA1B2C3D4E5:00000001"
}A controller's Problem(statusCode: 412) sends the same body.
A bare StatusCode(412) in an [ApiController] also gets a ProblemDetails body automatically; Results.StatusCode(412) in a minimal API sends an empty body unless you add UseStatusCodePages().
Setup
app.UseStaticFiles();Request
GET /file.txt HTTP/1.1
If-Match: "nope"Response (recorded)
HTTP/1.1 412 Precondition FailedThe precondition fails, so the file is not sent. Your own endpoints do not get this for free; compare ETags yourself for optimistic concurrency.
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