Explain the ASP.NET MVC request life cycle.
Quick Answer
The request is matched by routing to a controller and action, the controller factory creates the controller, the action invoker runs authorization and action filters, performs model binding and validation, executes the action method, gets back an ActionResult, runs result filters, and the result executes — a view result renders Razor to HTML which is written to the response.
First, routing takes the URL and works out which controller and action to call. Then the controller is created — through DI in Core. Before the action runs, the framework runs authorization filters, does model binding to fill the action parameters from the request, runs validation into ModelState, and then runs any action filters. The action method executes and returns an ActionResult. After that, result filters run and then the result executes — for a ViewResult that means the Razor engine renders the view with the model into HTML and writes it to the response. Exception filters sit around the action and result steps. In ASP.NET Core all of this happens inside the endpoint middleware, so the middleware pipeline runs around the outside.
In order:
- Routing — the URL is matched against the route table to produce route values, including
controllerandaction. - Controller creation — the controller factory (backed by DI in Core) instantiates the controller.
- Authorization filters —
[Authorize]and friends run first; they can short-circuit with a 401/403. - Model binding — route values, query string, form body and headers are mapped onto the action's parameters.
- Validation — data annotations and
IValidatableObjectpopulateModelState. - Action filters —
OnActionExecutingbefore,OnActionExecutedafter. - Action execution — your method runs and returns an
IActionResult. - Result filters —
OnResultExecuting/OnResultExecuted. - Result execution —
ViewResultlocates the view, runs the Razor view engine with the model, and writes HTML;JsonResultserialises;RedirectResultsends a 302; etc. - Exception filters wrap steps 6–9 and can convert an exception into a result.
In ASP.NET Core this whole sequence sits inside the endpoint middleware, so the middleware pipeline (routing, auth, etc.) runs around it.
Practise the whole thread the way an interviewer walks it — each question builds on the last.
- What is ASP.NET MVC?
- Explain the ASP.NET MVC request life cycle.You are here
- What is routing in ASP.NET MVC?
- What is ActionResult in ASP.NET MVC?
- What is the difference between ViewBag, ViewData and TempData?
- What is a strongly typed view in ASP.NET MVC?
- How does model validation work in ASP.NET MVC?