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

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.

主站蜘蛛池模板: 辛集市| 怀柔区| 贡山| 泸西县| 泌阳县| 高唐县| 连江县| 玉田县| 建始县| 沙坪坝区| 义马市| 大兴区| 金乡县| 太仓市| 枝江市| 凉山| 偏关县| 富源县| 伽师县| 中超| 和顺县| 济宁市| 仙桃市| 高陵县| 会宁县| 巴彦县| 象山县| 阜新| 苏尼特左旗| 瓮安县| 汽车| 广河县| 田阳县| 石屏县| 博罗县| 淄博市| 宁国市| 诸暨市| 塔城市| 甘泉县| 晋宁县|