In my case it works when I delete the "http" of the "profiles" section in launchSettings.json like this:
How to fix this error "warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3] Failed to determine the https port for redirect."
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
9 answers
Sort by: Most helpful
-
-
Zhi Lv - MSFT 32,036 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 usingdotnet run
command to run the application, it will run the application on Kestrel Development environment and the request url is setting via theapplicatonUrl
property.For example, according to the tutorial, I create a sample on my side, the result as below:
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 tohttp://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
-
Wesley Ford 35 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" } } } }
-
Moeez Abdul 20 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
-
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 solveddotnet tool install -g Microsoft.dotnet-httprepl dotnet dev-certs https --trust