'Why is UseHttpsRedirection using the wrong port when running from VS

RELATED

I am calling WebApplication.UseHttpsRedirection from Program.cs, but asp.net is redirecting to the default port 5001, instead of the port specified in appsettings.json and used by the application, when I build & run from VS.. Redirection works as expected when run directly from the (Debug) build folder

Configuring Endpoints

No launchSettings.json / .NET 6.0

appsettings.json:

{
 "Logging": {
 "LogLevel": {
  "Default": "Information",
  "Microsoft.AspNetCore": "Warning"
  }
 },
 "AllowedHosts": "*",
 "Kestrel": {
  "Endpoints": {
   "Http": {
    "Url": "http://localhost:5005"
   },
  "Https": {
    "Url": "https://localhost:5010"
   }
  },
  "Certificates": {
   "Default": {
    "Path": "localhost.pfx",
    "Password": "Testing"
   }
  }
 }
}

enter image description here

This is the redirect after hitting http://localhost:5005

enter image description here

That, off course, can not be shown as no one is listening...

https://127.0.0.1:5010 works fine



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source