ASP.NET MVC4 doesn't have a page life cycle like regular aspx pages do. How does one make use of preinit, init, prerender in MVC4?
Is there any type of life cycle in MVC4?
No, there is no page life cycle per se (because there is no 'page' object), but there is a request processing pipeline, which usually goes something like this:
System.Web.Routing.UrlRoutingModule
which uses the request url to map the request to a controller action method.OnActionExecuting
-methods of action filters on the controller and/or action are invokedOnActionExecuted
and OnResultExecuting
-methods of action filters are invokedActionResult
returned by the action method (typically, a ViewResult
which renders HTML) is executed.OnResultExecuted
-methods of action filters are invoked.The list above is just a rough sketch:
Routing: The mapping of an incoming request to the action method of an MVC controller is a story in and of itself. See ASP.NET Routing on MSDN for more info.
Action filters: There are action filters for authorization, output caching, error handling etc., all of which run at a certain time. This time see Filtering in ASP.NET MVC on MSDN for more info.
ASP.NET:
And, of course there's still all the traditional ASP.NET application events. Hence, HTTP modules like good old System.Web.Security.FormsAuthenticationModule
and System.Web.Caching.OutputCacheModule
, may still take part in the processing of a request.
If you want to really delve into the details, download the source code for the ASP.NET web stack from CodePlex. Much of what you are after will be in the System.Web.Mvc.ControllerActionInvoker
class, which, despite the scary name, isn't too hard to follow.
See Dejan's answer for a link to a good diagram that sums up much of this.
Global.asax.cs
file, when our request is matched by one of these map routes we are forward onMsdn documentation can be found on http://msdn.microsoft.com/en-us/library/dd381612(v=vs.98).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With