I have an ASP.NET Core 5 MVC app, running fine on a IIS 10 server.
I've been asked to enable HTTPS and enforce it on port 6443. I have been given the certificate and configured it on IIS.
When going into Chrome locally on the server and going to http://localhost
, you get correctly redirected to https://localhost:6443
Binding is configured:
Certificate is ok and locally it works.
When from another location in the network i visit the ip address of the server, if I visit it in https, it works.
If I visit in http, I get this chrome error:
ERR_CONNECTION_REFUSED, check connection or proxy.
This does not make any sense, before enabling https, it was working fine on http:80, and locally, the redirection works.
This is how it's done in code (Startup.cs):
public void Configure(IApplicationBuilder app)
{
if (appOptions.HttpsRedirectionEnabled)
{
app.UseHttpsRedirection();
}
// The default HSTS value is 30 days. You may want to change
// this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
and
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpsRedirection(options =>
{
options.RedirectStatusCode = StatusCodes.Status301MovedPermanently;
options.HttpsPort = 6443;
});
}
Also, visiting https://serverip seems to not work aswell, kinda like redirecting on 443 instead of 6443. So I get it working only locally.
I don't want to install any url rewrite stuff, this has to work normally.
What config I am missing on IIS or whatever else?
EDIT: been asked to add trace from chrome dev tools, here it is:
More detailed trace
Chrome hsts section:
But querying this finds stuff
As discussed in the comments, the browser had cached an HSTS response for the server, telling it to always request the secure version of the site. As per RFC 6797, this will only ever redirect to port 443
.
Disabling the HSTS headers and clearing the cached response from Chrome (using the chrome://net-internals/#hsts
settings page) resolved the issue.