ASP.NET Core Interview Question #101

What is routing in ASP.NET Core?

Routing, Controllers & Model Binding Mid-Level Intermediate

Quick Interview Answer

Routing is the mechanism that matches an incoming HTTP request to an application endpoint and can also generate URLs for endpoints.

Detailed Explanation

Routing is the mechanism that matches an incoming HTTP request to an application endpoint and can also generate URLs for endpoints.

ASP.NET Core supports conventional controller routing, attribute routing, Razor Pages routes, and route patterns used by minimal APIs. A route can contain literal segments, parameters, optional values, defaults, and constraints.

In MVC applications, routing normally determines the controller, action, and route values that should handle a request.

Code Example

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