In Chapter 1, Getting Started with ASP.NET Core, we talked about the OWIN pipeline, explaining that we use middleware to build this pipeline. It turns out that there is an MVC middleware that is responsible for interpreting requests and translating them into controller actions. To do this, we need a routing table.
There is only one routing table, as can be seen in this example from the default Visual Studio template:
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
What do we see here? The UseEndpoints extension method of IApplicationBuilder has a parameter that is an instance of IEndpointRouteBuilder, which lets us add routes to it. A route essentially comprises the following components:
- A name (default)
- A template pattern ({controller=Home}/{action=Index}/{id?...