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

Vaishnavi P 50 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,239 questions
{count} votes

9 answers

Sort by: Most helpful
  1. Mehmet Cenk Yenikoylu 5 Reputation points
    2023-12-11T11:00:56.1+00:00

    I changed the order of HTTP and HTTPS profile definitions. And as seen in the screenshot, both ports started to work actively. However, a new WARN appeared on the console.

    Screenshot 2023-12-11 at 1.40.13 PM

    1 person found this answer helpful.

  2. Scott Zeta 5 Reputation points
    2024-03-21T08:03:39.9433333+00:00

    Run

    dotnet run --launch-profile https
    

    Both ports are valid in browser and httpreplScreenshot 2024-03-21 at 18.18.01 If you are going to do Razor app tutorial

    dotnet watch --launch-profile https
    

    This can work as well, but if you try to access the page in http port in browser you will be redirect to https port. I guess because http page is not encouraged in browser anymore.

    Unless you comment out this line in Program.cs

    app.UseHttpsRedirection();
    

    Then you can vist pages under different protocals.

    Reference: https://github.com/dotnet/sdk/issues/29569

    1 person found this answer helpful.
    0 comments No comments

  3. Doris Ann Augustine 0 Reputation points
    2023-09-28T15:17:48.9333333+00:00

    Has anyone been able to solve this? All the solutions above didn't work for me.


  4. Giray Turker 0 Reputation points
    2024-05-01T01:40:34.87+00:00

    Watch dotnet run if there is https connection setting for existing project with;

    dotnet watch -lp https
    

    if you have profile for https, the connection automatically will open with your browser. Otherwise, create new https connection!

    If https connection exist:

    1 - Open the launchSettings.json file.

    2 - Find the section where your profiles are listed.

    3 -Change the order of the profiles so that the HTTPS profile is listed first.

    4 - Save the changes to the launchSettings.json file.

    Screenshot 2024-04-30 212738

    RESULT:

    Screenshot 2024-04-30 213001

    0 comments No comments