Other 3xx codes
All HTTP status codes in ASP.NET Core
3xx Redirection
Like 302, but the client must repeat the request with the same method and body at the new URL.
In ASP.NET Core: UseHttpsRedirection sends it by default. Redirect(url, preserveMethod: true) returns it.
The StatusCodes constant, HttpStatusCode enum name, reason phrase, class, and how EnsureSuccessStatusCode() and the standard resilience handler treat 307.
| Constant | StatusCodes.Status307TemporaryRedirect |
|---|---|
| HttpStatusCode | HttpStatusCode.TemporaryRedirect, HttpStatusCode.RedirectKeepVerb (aliases, same value) |
| Reason phrase | Kestrel sends Temporary Redirect |
| Class | 3xx, redirection |
| IsSuccessStatusCode | false |
| EnsureSuccessStatusCode() | throws HttpRequestException: Response status code does not indicate success: 307 (Temporary Redirect). |
| Standard resilience handler | does not retry it |
| HttpClient redirect | GET: followed, as GET. POST: followed, as POST. |
Results.StatusCode(StatusCodes.Status307TemporaryRedirect)
Results.Problem(statusCode: StatusCodes.Status307TemporaryRedirect, detail: "...")StatusCode(StatusCodes.Status307TemporaryRedirect)
Problem(statusCode: StatusCodes.Status307TemporaryRedirect, detail: "...")Checked on Kestrel: Results.Redirect(url, preserveMethod: true), ControllerBase.RedirectPreserveMethod(url) return 307.
What Results.Problem(statusCode: 307) sends (with AddProblemDetails()), as application/problem+json:
{
"title": "Temporary Redirect",
"status": 307,
"traceId": "0HNA1B2C3D4E5:00000001"
}A controller's Problem(statusCode: 307) sends a different body, because MVC only fills type and title for codes in ApiBehaviorOptions.ClientErrorMapping:
{
"status": 307,
"traceId": "0HNA1B2C3D4E5:00000001"
}Setup
builder.Services.AddHttpsRedirection(o => o.HttpsPort = 5001);
app.UseHttpsRedirection();Request
GET http://localhost:5000/ HTTP/1.1Response (recorded)
HTTP/1.1 307 Temporary Redirect
Location: https://127.0.0.1:5001/HTTPS redirection uses 307 Temporary Redirect by default, not 301, so browsers do not cache it and POSTs keep their method and body.
Fix: For a permanent redirect in production, set RedirectStatusCode = StatusCodes.Status308PermanentRedirect (and add HSTS).
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