Conventional routing

In the conventional routing style, during application startup, you define route templates that will be queried each time an incoming request is received in order to make a URL matching. This process will eventually map to a controller and a method inside it. If no route is found for the incoming request, an HTTP error of 404 (Not Found) will be returned to the caller.

When you called AddMvc inside the ConfigureServices method and the UseMvcWithDefaultRoute  method inside the Configure method in your startup class, at the same time, behind the scenes, the MVC framework added a route handler and set the route to the default template, which looks like this:

"{controller=Home}/{action=Index}/{id?}"

This template defines that for every request that is received, the request pipeline will attempt to break its URL so that the first part will be mapped to the controller name, the second part (the one after the /) will be mapped to the method inside the controller, and the third part, if it exists, will be used as a route parameter (enclosed in curly braces {}) to map to a parameter with the id method.

When ASP.NET Core searches for a controller, it takes the controller part from the template and concatenates it with the suffix controller. This means that, instead of using a URL in the form of /ExampleController/SomeAction, you can just write /Example/SomeAction.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.17.27