Hi @LOGAN PANUCAT,
404 means the requested url cannot be found on the server. You need check if your app actually contains such endpoint with requested route /
.
Note: If you use default WEB API project template, there is no route for /
which is quite different with MVC Project.
Default WEB API project with target framework .net 8 or lower, it will integrate with Swagger
, you can access the url:https://localhost:7211/swagger/index.html
.
Default WEB API project with target framework .net 9, it will integrate with OpenAPI
, you can access the url:http://localhost:7211/openapi/v1.json
.
Only if you define the endpoint like the following examples, you can access the url /
.
For Example:
Open your Program.cs
(or Startup.cs
if using an older version) and check if you have the following code.
app.MapGet("/", () => "Hello, World!");
Or check your controller if define the route like below:
[ApiController]
[Route("api/[controller]")] // This is the default route for this controller
public class TestController : ControllerBase
{
[HttpGet("/")] // This explicitly maps to the root `/`
public IActionResult Root() => Ok("Welcome to my API!");
[HttpGet] // This will respond to `/api/test`
public IActionResult Get() => Ok("This is the Test API.");
}
More details you could refer to the official document for better understanding:
Get Started with ASP.NET Core WEB API
Attribute routing for REST APIs
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,
Rena