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

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.

主站蜘蛛池模板: 双江| 康平县| 成武县| 盐源县| 昭通市| 大城县| 雷波县| 常州市| 通河县| 宁陕县| 太保市| 平塘县| 平阳县| 保定市| 镇赉县| 正宁县| 胶南市| 正安县| 南皮县| 楚雄市| 新邵县| 安阳市| 巴青县| 襄城县| SHOW| 锦屏县| 舒城县| 茶陵县| 密云县| 甘孜县| 胶州市| 南陵县| 百色市| 綦江县| 巴塘县| 高州市| 万山特区| 昌吉市| 仁布县| 托克逊县| 历史|