Reputation: 4563
When I create a new ASP.NET Core Web Application
and choose API
project template and run it, it routes to http://localhost:64221/weatherforecast
. May I know where it configures the default routing to weatherforecast
web api? In the configure
method, I don't see any default routing to weatherforecast
.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
Upvotes: 0
Views: 760
Reputation: 27825
May I know where it configures the default routing to weatherforecast web api?
In the Configure
method of Startup class, you can find that endpoints.MapControllers()
method is called, which only maps controllers that are decorated with routing attributes.
And in WeatherForecastController
class, you would find [Route("[controller]")]
is applied to it, like below.
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
Besides, you can check the source code of MapControllers(IEndpointRouteBuilder)
method and know how it works.
Upvotes: 2
Reputation: 470
the route is configured in launchSettings.json , you can find it in properties
and those are the attributes that you can change to get another route
"applicationUrl": "http://localhost:5002","launchUrl": "swagger",
Upvotes: 4