Enforce HTTPS in ASP.NET Core: Use Status308PermanentRedirect (#31739)

* Enforce HTTPS in ASP.NET Core: Use Status308PermanentRedirect

The previous paragraph says
> Use the fields of the [StatusCodes](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.statuscodes) class for assignments to `RedirectStatusCode`.

But the sample code then uses the status code defined in `System.Net` and a cast to `int`.

* Use Status307TemporaryRedirect in other sample code (Program2.cs)
pull/31924/head
Cédric Luthi 2024-02-27 20:24:17 +01:00 committed by GitHub
parent b76cb1bbcb
commit 68849ede7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -1,4 +1,4 @@
using System.Net;
using static Microsoft.AspNetCore.Http.StatusCodes;
var builder = WebApplication.CreateBuilder(args);
@ -15,7 +15,7 @@ builder.Services.AddHsts(options =>
builder.Services.AddHttpsRedirection(options =>
{
options.RedirectStatusCode = (int)HttpStatusCode.TemporaryRedirect;
options.RedirectStatusCode = Status307TemporaryRedirect;
options.HttpsPort = 5001;
});

View File

@ -1,4 +1,4 @@
using System.Net;
using static Microsoft.AspNetCore.Http.StatusCodes;
var builder = WebApplication.CreateBuilder(args);
@ -8,7 +8,7 @@ if (!builder.Environment.IsDevelopment())
{
builder.Services.AddHttpsRedirection(options =>
{
options.RedirectStatusCode = (int)HttpStatusCode.PermanentRedirect;
options.RedirectStatusCode = Status308PermanentRedirect;
options.HttpsPort = 443;
});
}