Other 4xx codes
All HTTP status codes in ASP.NET Core
4xx Client error
The URL exists but not for this HTTP method. The response must list the allowed methods in an Allow header.
In ASP.NET Core: Endpoint routing sends it, with Allow, when the path matches an endpoint for other methods only.
The StatusCodes constant, HttpStatusCode enum name, reason phrase, class, and how EnsureSuccessStatusCode() and the standard resilience handler treat 405.
| Constant | StatusCodes.Status405MethodNotAllowed |
|---|---|
| HttpStatusCode | HttpStatusCode.MethodNotAllowed |
| Reason phrase | Kestrel sends Method Not Allowed |
| Class | 4xx, client error |
| IsSuccessStatusCode | false |
| EnsureSuccessStatusCode() | throws HttpRequestException: Response status code does not indicate success: 405 (Method Not Allowed). |
| Standard resilience handler | does not retry it |
Results.StatusCode(StatusCodes.Status405MethodNotAllowed)
Results.Problem(statusCode: StatusCodes.Status405MethodNotAllowed, detail: "...")StatusCode(StatusCodes.Status405MethodNotAllowed)
Problem(statusCode: StatusCodes.Status405MethodNotAllowed, detail: "...")What Results.Problem(statusCode: 405) sends (with AddProblemDetails()), as application/problem+json:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.6",
"title": "Method Not Allowed",
"status": 405,
"traceId": "0HNA1B2C3D4E5:00000001"
}A controller's Problem(statusCode: 405) sends the same body.
A bare StatusCode(405) in an [ApiController] also gets a ProblemDetails body automatically; Results.StatusCode(405) in a minimal API sends an empty body unless you add UseStatusCodePages().
Setup
app.MapGet("/items", () => "items");Request
DELETE /items HTTP/1.1Response (recorded)
HTTP/1.1 405 Method Not Allowed
Allow: GETRouting knows /items exists for GET only, so it answers 405 with Allow: GET and an empty body.
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