We are exploring every single boring details about MVC routing in this section.
Demonstrates fixed routing and default conventional routing for ASP.NET MVC.
Use
endpoints.MapDefaultControllerRoute();
to specify default convention routing for ASP.NET MVC.The simplest example for attribute routing. We use the
Route
attribute at the Controller. This only allows you to have one Action per Controller.We use the
Route
attribute at Action methods (in contrast to previous example). This allows you to have multiple Actions in a Controller.Demonstrate the usage of
HttpGet
andHttpPost
.Demonstrate the usage of
[controller]
replacement token at theRoute
attribute.Demonstrate the usage of
[controller]
and[action]
replacement tokens at theRoute
attribute.Demonstrate the usage of
[action]
replacement tokens at theHttpGet
attribute.Demonstrate the usage of
IActionConstraint
attribute.The following map routing will search all HomeController.About action accross the assembly regardless of namespace. If you have multiple HomeController.About, it will generate error because the framework cannot decide which method to use. This sample demonstrates on how using a custom
IActionConstraint
attribute solves this problem.
dotnet6