Reputation: 41
How to use conventional and attribute routing in asp.net core web api?
Is it possible to combine both conventional and attribute routing similar to asp.net web api ?
How to specify default route in asp.net core web api?
Upvotes: 2
Views: 1316
Reputation: 741
According to official Microsoft documentation, Attribute routing becomes a requirement in Asp.net core web API applications.
You have to define attribute routes like below.
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
Actions are inaccessible via conventional routes defined by UseMvc or UseMvcWithDefaultRoute in Startup.Configure.
Upvotes: 3
Reputation: 3920
In asp.net core web api and mvc you can specify routing
You can specify default routing in launchSettings.json. Set controller name at launchUrl property for all the profiles
.net core 2.2, At Startup.cs configure method,
app.UseMvc(routes =>
{
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
.net core 3.1, At Startup.cs configure method,
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
Upvotes: 1