ASP.NET Core MVC Interview Question #23

What is conventional routing in ASP.NET Core MVC?

MVC Fundamentals, Controllers, Views & Routing Junior Beginner

Quick Interview Answer

Conventional routing defines route patterns centrally, usually in Program.cs. A common default pattern is {controller=Home}/{action=Index}/{id?}, which maps URL segments to controller and action names and makes the id segment optional.

Detailed Explanation

Conventional routing defines route patterns centrally, usually in Program.cs. A common default pattern is {controller=Home}/{action=Index}/{id?}, which maps URL segments to controller and action names and makes the id segment optional.

Conventional routing is convenient for applications whose controllers follow a consistent URL structure. More specific conventional routes should normally be registered before broader routes.

Code Example

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");