'How to fix 'Localhost not found' when using dotnet run?

I'm studying this learning module from microsoft Learning WEB API

But I'm not seeing anything when I try to run dotnet run command on vscode terminal.

Hence, I got this Error 404

This localhost page can’t be foundNo webpage was found for the web address: https://localhost:7162/ HTTP ERROR 404

But my terminal displays :

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7162
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5043
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\John\Desktop\ContosoPizza\



Solution 1:[1]

404 means the request url is not correct, your controller does not contain any url with empty string. If you use default pure Web Api project, it only contains one get method in WeatherForecastController. The request url should be https://localhost:portNum/WeatherForecast(or api/WeatherForecast.It depends on the [Route] attribute on your controller. You can check the controller).

From your description, I think you may misunderstand dotnet run command. It is just used to build the project. You need manually open the browser and then browse to correct url(e.g. https://localhost:7162/WeatherForecast).

Actually your shared document is very clear here: enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1