C
C#11mo ago
tthomas

.net core web api development in mac OS using VS Code

Getting "This localhost page can’t be found" error in browser when opening localhost:5200 in browser after running 'donet run' command. The server is running in 5200 port but browser can't find it. Help me with this.
No description
9 Replies
tthomas
tthomasOP11mo ago
in the console I can see that the server is running at 5200 port
tthomas
tthomasOP11mo ago
No description
tthomas
tthomasOP11mo ago
Anyone faced similar issue?
Cracker
Cracker11mo ago
there is no error actually there is no path specified for default route, therefore you get 404 what do you have in Program.cs and controller attributes ?
Lex Li
Lex Li11mo ago
A Web API usually has no web pages to serve, so 404 is natural.
tthomas
tthomasOP11mo ago
This is my program.cs file
No description
tthomas
tthomasOP11mo ago
Also i have this controller
No description
tthomas
tthomasOP11mo ago
@Lex Li @atakancracker - looks like issue is someth8ngs else as I already have the controller as above @Lex Li @atakancracker http://localhost:5200/WeatherForecast - this worked
Lex Li
Lex Li11mo ago
Web API projects are in general serving data via different HTTP requests/responses, so you should use a tool like curl to access the data, or use Swagger which is de facto approach. You found that URL worked, simply because your web browser sent the expected HTTP GET request at /WeatherForecast, and your Web API instance responded with a piece of JSON. Like @atakancracker commented, nothing is there to serve HTTP GET request at / so 404 is expected.

Did you find this page helpful?