Routing
In Chapter 2, we introduced how to create a simple ASP.NET Core web API project using the default controller-based template. The project uses some attributes, such as [Route("api/controller")]
, [HttpGet]
, and so on, to map incoming requests to the corresponding controller actions. These attributes are used to configure the routing for the ASP.NET Core web API project.
Routing is a mechanism that monitors incoming requests and determines which action method is to be invoked for those requests. ASP.NET Core provides two types of routing: conventional routing and attribute routing. Conventional routing is typically used for ASP.NET Core MVC applications, while ASP.NET Core web APIs use attribute routing. In this section, we will discuss attribute routing in more detail.
You can download the RoutingDemo
sample project from /samples/chapter3/RoutingDemo/
in the chapter's GitHub repository.
What is attribute routing?
Open the Program.cs
file in the RoutingDemo...