ASP.NET Core WebAPI default route not working
As @tmg mentioned, do the following:
Right click your web project -> Select Properties -> Select the Debug tab on the left -> Then edit the 'Launch Url' field to set your own default launch url.
You can change the default route by modifying LaunchSettings.json file as shown
Follow the steps below.
Create a base controller for your API that extends base controller of dotnet core:
using Microsoft.AspNetCore.Mvc;
namespace WebApi.Controllers
{
[Route("api/[controller]")]
public abstract class ControllerApiBase : Controller
{
}
}
And inherit the base class in your API controllers:
using Microsoft.AspNetCore.Mvc;
using WebApi.Dtos;
namespace WebApi.Controllers
{
public class PingController : ControllerApiBase
{
public PingDto Get()
{
return new PingDto
{
Version = "0.0.0"
};
}
}
}