官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 芮城县| 敦化市| 竹溪县| 当涂县| 石景山区| 天津市| 梧州市| 奉贤区| 娱乐| 合作市| 昔阳县| 益阳市| 盈江县| 河津市| 榆树市| 无锡市| 德清县| 河西区| 双辽市| 勃利县| 庆城县| 赫章县| 白山市| 台北县| 东至县| 乐清市| 鄂托克前旗| 邵阳市| 勐海县| 龙山县| 青冈县| 桃园市| 龙里县| 宜春市| 沾化县| 芜湖市| 舞钢市| 枣强县| 浦县| 清徐县| 商丘市|