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 the requests and translating them into controller actions. To do this, we need a routing table. There is only one routing table and it is configurable through the UseMvc
method, as can be seen in this example from the default Visual Studio template:
app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); });
What do we see here? The UseMvc
extension method of IApplicationBuilder
has a parameter that is an instance of IRouteBuilder
, which lets us add routes to it. A route is essentially comprised of the following components:
- A name (
default
) - A template (
{controller=Home}/{action=Index}/{id?}
) - Optional default values for each routing parameter (
Home
,Index
)
There are some optional...