AlexKibysz
AlexKibysz

Reputation: 43

ASP.NET Core 6 Web API : this localhost page can’t be found error when running the Web API

This localhost page can't be found webpage was found for the web address: http://localhost:5254/

HTTP ERROR 404

Program.cs

launchsettings.json

Upvotes: 3

Views: 14194

Answers (3)

Tuấn Vũ Quý
Tuấn Vũ Quý

Reputation: 57

You should add /swagger/index.html to the link:

http://localhost:5254/swagger/index.html 

Upvotes: 3

AlexKibysz
AlexKibysz

Reputation: 43

solution: add localhost/swagger,
vscode doesn't show swagger url on startup

Upvotes: 1

Fei Han
Fei Han

Reputation: 27825

This localhost page can't be found webpage was found for the web address: http://localhost:5254/ HTTP ERROR 404

In ASP.NET CORE WebAPI project, it does not configure default route or serve default document for root URL path, which cause above issue.

If you check the code of your API controller, you might find that the routes like below are defined.

[ApiController]
[Route("[controller]")]

or

[ApiController]
[Route("api/[controller]")]

To access specific endpoint, please check the actual route defined on that endpoint, you may need to include [controller] and [action] info in URL while you make request(s).

For more information about routing, please check: https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-6.0#attribute-routing-for-rest-apis

Upvotes: 4

Related Questions