What is the role of the ASP.NET worker process?
What is aspnet_wp.exe?

For faster execution of ASP.NET applications, that are primarily based to be hosted on IIS servers, the aspnet_wp.exe comes into picture. This file (aspnet_wp.exe) is actually the ASP.NET worker process. The worker process is introduced to actually share the load on the IIS, so that application domains and other services may be maintained by a single worker process.

The aspnet_wp.exe worker process is a part of the Microsoft ASP.NET framework, and it is responsible for most of the technical processes in the ASP.NET framework. There may be multiple instances of ASP.NET worker process running on IIS 6 (a process running as inetinfo.exe), depending on multiple application pools. The worker process handles all the requests passed to the ASP.NET framework, so we may say that its actually the main engine that handles all requests pertaining to ASPNET. For example, when a request for an .aspx page is recieved by the IIS server, the dll called aspnet_isapi.dll passes this request to the aspnet_wp.exe worker process.

Explain the page life cycle in ASP.NET 2.0

ASP.NET 2.0 Page Life Cycle - The lifetime of an ASP.NET page is filled with events. A series of processing steps takes place during this page life cycle. Following tasks are performed:

* Initialization
* Instantiation of controls
* Restoration & Maintainance of State
* Running Event Handlers
* Rendering of data to the browser

The life cycle may be broken down into Stages and Events. The stages reflect the broad spectrum of tasks performed. The following stages take place

1) Page Request - This is the first stage, before the page life cycle starts. Whenever a page is requested, ASP.NET detects whether the page is to be requested, parsed and compiled or whether the page can be cached from the system.

2) Start - In this stage, properties such as Request and Response are set. Its also determined at this stage whether the request is a new request or old, and thus it sets the IsPostBack property in the Start stage of the page life cycle.

3) Page Initialization - Each control of the page is assigned a unique identification ID. If there are themes, they are applied. Note that during the Page Initialization stage, neither postback data is loaded, nor any viewstate data is retrieved.

4) Load - If current request is a postback, then control values are retrieved from their viewstate.

5) Validation - The validate method of the validation controls is invoked. This sets the IsValid property of the validation control.

6) PostBack Event Handling - Event handlers are invoked, in case the request is a postback.

7) Rendering - Viewstate for the page is saved. Then render method for each control is called. A textwriter writes the output of the rendering stage to the output stream of the page's Response property.

8) Unload - This is the last stage in the page life cycle stages. It is invoked when the page is completely rendered. Page properties like Respone and Request are unloaded.

Note that each stage has its own events within it. These events may be used by developers to handle their code. Listed below are page events that are used more frequently.

PreInit - Checks the IsPostBack property. To create or recreate dynamic controls. To set master pages dynamically. Gets and Sets profile propety values.

Init - Raised after all controls are initialized, and skin properties are set.

InitComplete - This event may be used, when we need to be sure that all initialization tasks are complete.

PreLoad - If processing on a control or a page is required before the Load event.

Load - invokes the OnLoad event on the page. The same is done for each child control on the page. May set properties of controls, create database connections.

Control Events - These are the control specific events, such as button clicks, listbox item selects etc.

LoadComplete - To execute tasks that require that the complete page has been loaded.

PreRender - Some methods are called before the PreRenderEvent takes place, like

EnsureChildControls- data bound controls that have a dataSourceId set also call the DataBind method.

Each control of the page has a PreRender event. Developers may use the prerender event to make final changes to the controls before it is rendered to the page.

SaveStateComplete - ViewState is saved before this event occurs. However, if any changes to the viewstate of a control is made, then this is the event to be used. It cannot be used to make changes to other properties of a control.

Render - This is a stage, not an event. The page object invokes this stage on each control of the page. This actually means that the ASP.NET server control's HTML markup is sent to the browser.

Unload - This event occurs for each control. It takes care of cleanup activities like wiping the database connectivities.

No comments: