How to fix this error "warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3] Failed to determine the https port for redirect."

Vaishnavi P 80 Reputation points
2023-06-03T08:29:57.58+00:00

Good evening , I am trying to build a simple web api using ASP.Net . The app has been showing the error like this after building it -

warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
      Failed to determine the https port for redirect.

I have built according to this documentation-
https://learn.microsoft.com/en-in/training/modules/build-web-api-aspnet-core/3-exercise-create-web-api

Developer technologies | ASP.NET | ASP.NET Core
{count} votes

14 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Habeebullahi Lawal 0 Reputation points
    2025-01-24T10:40:15.7866667+00:00

    In the launchSettings.json file, move the https property to the top of the http property. Both of them will work and http requests will be redirected to the https port (as long as you don't disable the UseHttpsRedirection() in the Program.cs file).

    0 comments No comments

  3. Luis Changmarín Isaza 0 Reputation points
    2025-08-09T14:31:51.4+00:00

    Hi all,

    I would like to make a contribution to this thread since I've also been wrestling with this issue for a few days now and wanted to solve it on my own without entrusting or handling it to Copilot, Alexa or any assistant of any sort so I did some research.

    Bluntly:

    The First step is to install Swashbuckle package following the steps form MS learn:

    https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-8.0&tabs=visual-studio-code

    The Second step is to Trust the HTTPS development certificate by running

     dotnet dev-certs https --trust
    

    in Powershell as an admin. I was running the command in the VS Code terminal and wasn't working (Learn more at ASP.NET docs https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-9.0&tabs=visual-studio-code).

    The Third step is to launch the application with

    dotnet run --launch-profile https
    

    Reference:

    https://www.linkedin.com/pulse/fixing-https-issues-aspnet-core-say-goodbye-your-isnt-lokesh-1qtwc/

    I hope it works also for you.

    Regards,

    Ch.-


  4. Sanusha Sanusha 75 Reputation points
    2025-08-10T13:42:54.14+00:00

    Design design design design design design 1000096210

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.