warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3] Failed to
determine the https port for redirect. means the app calls
app.UseHttpsRedirection() but listens on HTTP only, so the middleware has no
HTTPS address to send the browser to. In the test it then served the request on plain
HTTP. Give it an HTTPS port and the redirect works.
Two fixes were tested: setting ASPNETCORE_HTTPS_PORT, and adding an
https:// address to --urls. Both turned the 200 into a
307 Temporary Redirect to the HTTPS port and the warning was gone.
The error
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://127.0.0.1:15709
...
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
Failed to determine the https port for redirect.
Why it happens
The app was the empty web template with one extra line:
var app = builder.Build();
app.UseHttpsRedirection();
app.MapGet("/", () => "Hello World!");
It was started with --urls http://127.0.0.1:15709, an HTTP address and
nothing else. The warning appeared in the log after the startup lines, once a request had
been made, and that request was not redirected: curl.exe -s -D - http://127.0.0.1:15709/ got
HTTP/1.1 200 OK and Hello World!. So the app kept working, but
the redirection you asked for silently did not happen. This is a warning, not an
exception, which makes it easy to miss in a busy log.
The fix
Fix A, tell the middleware the port with an environment variable (same code):
$env:ASPNETCORE_HTTPS_PORT='15716'; & ./run.ps1 https 15715; $env:ASPNETCORE_HTTPS_PORT=$null
curl.exe -s -D - http://127.0.0.1:15715/
HTTP/1.1 307 Temporary Redirect
Content-Length: 0
Date: Fri, 06 Nov 2026 07:55:11 GMT
Server: Kestrel
Location: https://127.0.0.1:15716/
Fix B, let the app listen on HTTPS too, with no port setting (this PC has the ASP.NET Core development certificate installed):
$env:FIXMODE='https'; $p2 = Start-Process -FilePath "$d/FixLab/bin/Debug/net10.0/FixLab.exe" -ArgumentList '--urls','"http://127.0.0.1:15717;https://127.0.0.1:15718"' -WorkingDirectory "$d/FixLab" -WindowStyle Hidden -RedirectStandardOutput "$d/logs/https2-out.txt" -RedirectStandardError "$d/logs/https2-err.txt" -PassThru; Start-Sleep 3
curl.exe -s -D - http://127.0.0.1:15717/
HTTP/1.1 307 Temporary Redirect
Content-Length: 0
Date: Fri, 06 Nov 2026 07:55:14 GMT
Server: Kestrel
Location: https://127.0.0.1:15718/
In both runs the log had no warning line after startup. run.ps1 is the test's
own script; its start line is
$p = Start-Process -FilePath $exe -ArgumentList "--urls", "${Url}:$Port" -WorkingDirectory (Join-Path $root "FixLab") -WindowStyle Hidden -RedirectStandardOutput "$out\$Mode-out.txt" -RedirectStandardError "$out\$Mode-err.txt" -PassThru,
after $env:FIXMODE = $Mode, with $Url defaulting to
http://127.0.0.1. In fix B, $d is the test folder. Note that fix A only sets where the redirect points: nothing in that run listened on
15716, so a browser following that redirect would have reached a closed port. Fix A fits
when something else in front of the app serves HTTPS on that port; with fix B the redirect
pointed at an address the app itself was listening on, as the second
Now listening on: https://127.0.0.1:15718 line showed.
How it was reproduced
A dotnet new web project (net10.0) with the three lines above, built once and
started directly in the Production environment, called with curl 8.21.0. .NET SDK
10.0.403, Microsoft.AspNetCore.App 10.0.14, Windows 11.
Frequently asked
- Does 'Failed to determine the https port for redirect' break my app?
- Not in the test. The request was served over plain HTTP with 200 OK; only the redirect to HTTPS did not happen, and a warning was logged.
- How do I set the HTTPS port for UseHttpsRedirection?
- Setting the environment variable ASPNETCORE_HTTPS_PORT=15716 made the app answer 307 with Location: https://127.0.0.1:15716/. Listening on an https:// URL as well also worked.
- Does ASPNETCORE_HTTPS_PORT make the app listen on HTTPS?
- No. In the test it only changed the Location of the redirect to https://127.0.0.1:15716/. Nothing listened on 15716; to serve HTTPS from the app itself, add an https:// URL.
More decoded errors in the Fixes category. For where the app's addresses come from, see Kestrel ports and URLs.