HTTPS redirection problem with IOS and .net core 2.1

When working with a .net core 2.1 site, I discovered that HTTPS redirection was working with browsers on Windows computers, but not on IOS machines. This behavior can be difficult to detect if your browser is pulling the URL from its cache. The problem existed for both Chrome, Firefox, and Safari on IOS.

Redirection code fix

As in earlier .Net Core versions, the Configure method in Startup.cs contains:

Now, in addition, I change the IWebHostBuilder line in program.cs to this.

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
.UseSetting(“https_port”, “443”)

The .UseSettings option is needed to directly set the port even though port 443 is normally used for HTTPS URLs as a default. It appears that the port must be explictly set in .net core 2.1.

Making this change allowed browsers on IOS computers and devices to also properly redirect to HTTPS.

Leave a Reply

Your email address will not be published. Required fields are marked *