ASP.NET Core MVC Interview Question #3

How does a request flow through an ASP.NET Core MVC application?

MVC Fundamentals, Controllers, Views & Routing Junior Beginner

Quick Interview Answer

An HTTP request first enters the ASP.NET Core middleware pipeline. Routing identifies a matching endpoint, and MVC then selects the appropriate controller and action. Model binding creates action parameters from request data, validation runs, filters execute at their defined stages, and the action method produces an IActionResult or another supported result.

Detailed Explanation

An HTTP request first enters the ASP.NET Core middleware pipeline. Routing identifies a matching endpoint, and MVC then selects the appropriate controller and action. Model binding creates action parameters from request data, validation runs, filters execute at their defined stages, and the action method produces an IActionResult or another supported result.

If the action returns a ViewResult, the Razor view engine locates and renders the view. The generated response then travels back through the middleware pipeline to the client.

Code Example

app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();

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