1 February 2014

About Asp.net Page life cycle

Asp.net Page Execution :

   As the request comes from Client (Browser) and sends to Server (we call it as Web server) in turn server process the request and sends response back to the client in according to the client request.

Internally Interesting Process Happens. To Know this Process we need to know the architecture of the IIS(Internet Information System)


It Consists of Three Parts
  • Inetinfo.exec
  • ISAPI Filer (Container for Internet Server Application Interface dlls),
  • Worker Process (aspnet_wp.exe)
Inetinfo.exec:
    When Client makes are request first Inetinfo.exec  asp.net request handler with the request.when the request is for the static resources like HTML files or image files inetinfo.exe process the request and sent to client.if the Request contains the extension such as .asp,.aspx then it will processes the request to API filter

ISAPI Filer (Container for Internet Server Application Interface dlls):

    ISAPI filter will have several runtime modules called as ISAPI extensions. To process the request ISAPI filter takes the help of these runtime modules. The runtime module loaded for ASP page is asp.dll. And for ASP.NET page it's ASPNET_ISAPI.dll. From here the request is processed to the "worker process". Worker Process will have several application domain.

Application Domain
      
  The purpose of the application domain is in order to isolate one application from another. Whenever we create a new application, application domains are created automatically by the CLR Host. Worker process will create a block of memory related to particular application. Application domains provide a more secure and versatile unit of processing that the common language runtime can use to provide isolation between applications. 

      Application domains are normally created by runtime hosts. Runtime host is responsible for bootstrapping the common language runtime before an application is run.

       Worker process sends the request to HTTP PIPE line.(HTTP Pipeline is nonetheless collection of .net framework classes). HTTP Pipeline compiles the request into a library and makes a call to HTTP runtime and runtime creates an instance of page class

public class File : System.Web.UI.Page{}

 ASP.Net web page is a class derived from page class, this page class resides in system.web.dll

 After creating instance pf page class HTTP Runtime immediately invokes process request method of page class

Page Req = new Page();
Req.ProcessRequest(); 

Process Request Method does following things:

  1) Intialize the memory
  2) Load the view state
  3) Page execution and post back events
  4) Rendering HTML content
  5) Releasing the memory

Process Request Method executes set of events for page class .These are called as Page life cycle events.

Page Life Cycle Events:


Page_Init

    The server controls are loaded and initialized from the Web form's view state. This is the first step in a Web form's life cycle.


Page_Load

       The server controls are loaded in the page object. View state information is available at this point, so this is where you put code to change control settings or display text on the page.


Page_Pre Render
     
      The application is about to render the page object.


Page_Unload

      The page is unloaded from memory.


Page_Disposed

      The page object is released from memory. This is the last event in the life of a page object.


Page_Error

      when unhandled exception occurs.


Page_Abort Transaction

      A transaction is aborted.


Page_Commit Transaction

      A transaction is accepted.


Page_Data Binding

      A server control on the page binds to a data source. 
      Process Request Method finally renders HTML Page. 


Dependencies:
     
      When the request comes to ASP.net worker process, it will be forwarded to HTTP Application factory. This "Application Factory" will maintain address of the application domains which are currently executing under worker process. If the required virtual directory application domain is unavailable it will create a new application domain. If the application domain is already existing, the request will be forwarded to corresponding AppDomain.

      Application Domain maintains page handler factory class. This will contain all libraries addresses corresponding to webpage. If the requested webpage library is available the instance of the page class is created, if the library is unavailable the request will be forwarded to HTTP pipeline.


No comments:

Post a Comment