Fix “Failed to Determine the HTTPS Port for Redirect” in ASP.NET Core

Quick answer. Configure the actual public HTTPS port when the app owns the redirect. When a proxy terminates TLS, verify forwarded scheme handling and decide which layer should own redirects.

Applies to. ASP.NET Core

Hosting and build diagnosticsConfirm public HTTPS URLConfigure redirect ownerTest Location header
Confirm public HTTPS URL → Configure redirect owner → Test Location header

What does the error look like?

HTTP requests reach UseHttpsRedirection, but the middleware cannot infer a reachable HTTPS port.

How do you diagnose the cause?

Check app URLs, endpoint discovery, and proxy HTTPS routing. A development HTTPS port is usable only if that endpoint is actually listening. Behind a proxy, process trusted forwarded headers before redirect middleware to avoid loops.

Worked example

Use the relevant portion below in a development or staging environment. Match the existing application’s packages, settings, and environment before applying the change.

C#
builder.Services.AddHttpsRedirection(o => o.HttpsPort = 443);
// Use 443 when this is the real externally reachable HTTPS port.

In Blogger preview, you can select the snippet and copy it directly.

How do you verify the fix?

CheckExpected behavior
Test Location headerThe HTTP request redirects once to the reachable HTTPS URL.
Repeat with the original failing input or setupThe relevant error is reproducible under the old conditions and resolved under the corrected conditions

These are expected results to validate in your environment.

What should you check first if the error returns?

Configure the actual public HTTPS port when the app owns the redirect. When a proxy terminates TLS, verify forwarded scheme handling and decide which layer should own redirects.

Official documentation · ASP.NET tutorials

Comments