I have an IIS .NET application listening on two ports:
- http port 8282 (a legacy link)
- https port 8283
I would like to redirect the http port to the https binding.
I have created a redirect rule as per below. I have also disabled "Enforce SSL".
When I try to access the app via http the url changes from http to https but the port stays the same. Edge browser returns this error:
The connection for this site is not secure sent an invalid response. ERR_SSL_PROTOCOL_ERROR
Redirect rule:
<rewrite>
<rules>
<rule name="HTTPS force" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
I also tried adding the following in Program.cs
builder.Services.AddHttpsRedirection(options =>
{
options.RedirectStatusCode = (int)HttpStatusCode.PermanentRedirect;
options.HttpsPort = builder.Configuration.GetValue<int>("https_port");
});