C
C#9mo ago
Timberfist

New webapi Project Doesn't Listen On https Port

I'm working through the "Create a web API with ASP.NET Core controllers" module on Microsoft Learn (https://learn.microsoft.com/en-gb/training/modules/build-web-api-aspnet-core/). I've created a new project using dotnet new webapi -controllers -f net8.0and run it using dotnet run. The module states that I should see something like this in the terminal:
Building...
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7294
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5118
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
Building...
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7294
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5118
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
The two lines relating to https are missing for me. If I attempt to connect to the service using https://localhost:7294/weatherforecast then the connection times out. According to the module, this should work. If I connect to http://localhost:5118/weatherforecast then it works fine. I checked that I have a trusted development certificate with dotnet dev-certs https --check --trust and it reports that I do. If I open "Manage Certificates" in Microsoft Edge, I can see it. Does anyone have any idea why my service is not listening on the https port?
6 Replies
Timberfist
TimberfistOP9mo ago
I just rechecked the error message when attempting to connect to https://localhost:7294/weatherforecast and it's not a timeout, it's "localhost refused to connect" - ERR_CONNECTION_REFUSED.
Pobiega
Pobiega9mo ago
look for a launchSettings.json file, usually in the "Properties" subfolder of your project.
Timberfist
TimberfistOP9mo ago
OK, now I understand. So the launchSettings.json file defines multiple launch profiles. The first profile (which is http only) is selected by default. Alternate profiles can be launched by specifying them on the command line thus: dotnet run --launch-profile "https". Now I just need to work out how to specify which profile I want to launch from Visual Studio Code.
Pobiega
Pobiega9mo ago
I wouldn't recommend using VS Code with C# personally, and if you still do, you'd use dotnet run to start it.. that might have changed with the new devkit extension thou alternatively make the https profile the default by just moving them around
Timberfist
TimberfistOP9mo ago
It's pretty good but I've not compared it to Visual Studio yet. There certainly seem to be a few things I'm encountering in the Microsoft Learn modules that just don't make sense to me which, in some cases at least, I suspect is because they're written with the expectation that the reader is using Visual Studio.
Pobiega
Pobiega9mo ago
Yeah. The new devkit extension is still quite new and pre-that it was kinda rough using VS C Most official sources will assume full VS, and it remains the "recommended unless you know what you are doing" IDE
Want results from more Discord servers?
Add your server