ASP.NET Core Interview Question #102
What is conventional routing in ASP.NET Core MVC?
Routing, Controllers & Model Binding Mid-Level Intermediate
Quick Interview Answer
Conventional routing defines route patterns centrally, usually in Program.cs. The pattern is applied across controllers and actions according to naming conventions.
Detailed Explanation
Conventional routing defines route patterns centrally, usually in Program.cs. The pattern is applied across controllers and actions according to naming conventions.
A common default route is {controller=Home}/{action=Index}/{id?}. The defaults mean that / can resolve to HomeController.Index, while /Products/Details/10 can resolve to ProductsController.Details with id equal to 10.
Conventional routing is convenient for applications whose controllers follow a consistent URL structure.
Code Example
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");