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

Vaishnavi P 30 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

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,144 questions
{count} votes

8 answers

Sort by: Most helpful
  1. Erick A. Capitanachi González 65 Reputation points
    2023-10-22T15:46:50.16+00:00

    In my case it works when I delete the "http" of the "profiles" section in launchSettings.json like this:

    User's image

    13 people found this answer helpful.
    0 comments No comments

  2. Zhi Lv - MSFT 32,011 Reputation points Microsoft Vendor
    2023-06-05T05:27:35.1366667+00:00

    Hi @Vaishnavi P

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

    From the issue message, it seems that you might not specified the HTTPS port in your configuration or if you have multiple HTTPS ports in your server configuration.

    Check the Properties/launchSettings.json file, when using dotnet run command to run the application, it will run the application on Kestrel Development environment and the request url is setting via the applicatonUrl property.

    User's image

    For example, according to the tutorial, I create a sample on my side, the result as below:

    User's image

    You can try to change the port in the applicationUrl.

    ASP.NET Core projects are configured to bind to a random HTTP port between 5000-5300 and a random HTTPS port between 7000-7300. This default configuration is specified in the generated Properties/launchSettings.json file and can be overridden. If no ports are specified, Kestrel binds to http://localhost:5000. More detail information, see Configure endpoints for the ASP.NET Core Kestrel web server.

    Finally, if still not working, can you tell us which version of the .NET SDK you are using? And it is better to create a simple sample to reproduce the problem and share it with us, it is easier for us to help you find the issue.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Dillion

    11 people found this answer helpful.

  3. Wesley Ford 30 Reputation points
    2023-11-27T19:33:08.65+00:00

    I solved this by adding the following to my appsettings.json to configure [Kestrel] the default webserver for ASP.NET

    {
      "Kestrel": {
        "Endpoints": {
          "Https": {
            "Url": "https://localhost:5001"
          }
        }
      }
    }
    
    
    6 people found this answer helpful.

  4. yehonatan yehezkel 20 Reputation points
    2023-07-11T10:50:21.6133333+00:00

    on my windows machine this warning was because i did not add certification to the cert center
    after this 2 steps it solved

    dotnet tool install -g Microsoft.dotnet-httprepl
    dotnet dev-certs https --trust
    
    3 people found this answer helpful.

  5. Moeez Abdul 10 Reputation points
    2024-04-02T10:15:52.03+00:00

    In my case, I just ran this command in my CLI from the Root Directory, and it just Fired up:

    dotnet watch -lp https 
    

    CLI Image

    2 people found this answer helpful.
    0 comments No comments