The Webclass Life Cycle

Like a form-based application, a webclass is initialized and destroyed, although these events are fired differently than they are for a form. In addition, a webclass has several other events that mark stages in its life, indicating when the browser displays the first webitem and when requests are received and processed.

These are the key events in the life of a webclass:

  1. The Initialize event occurs when an end user accesses the .asp (Active Server Pages) file that acts as the host for your IIS application. In the Initialize event, the webclass is created as an object. This is always the first event in the webclass's lifetime.

    Note   If the StateManagement property for the webclass is set to wcNoState, the webclass fires the Initialize event each time it receives an HTTP request. See "State Management in IIS Applications" for more information about setting the StateManagement property.

  2. The BeginRequest event is the next event called after the Initialize event when the user starts the application, and is also fired each time the webclass receives a subsequent request from the browser. This event marks the beginning of processing for an HTTP request. You might use this event to perform processing required for every request the webclass will perform. For example, you could use BeginRequest to retrieve state information from a database or to verify user information before processing a request.

  3. The Start event generally occurs the first time BeginRequest is fired in the application. It is not fired on subsequent requests. This event is generally used to send an initial response to the browser, launching the Respond event for the specified webitem.

    Note   If the end user specifies a webitem and event in the initial URL they use to launch the application, the webclass does not fire the Start event. In this case, the specified event would be the first event fired. See "Setting the Start Event" for more information.

  4. The EndRequest event occurs when the webclass has finished processing an HTTP request and has returned a response to the client. The processing of an event might require the webclass to process several templates or webitems and their associated event procedures before a response is returned to the client.

  5. The Terminate event tells the run-time DLL to destroy the instance of the webclass.

    Note  If the StateManagement property for the webclass is set to wcNoState, the webclass fires the Terminate event each time it sends a response to the browser. If the StateManagement property for the webclass is set to wcRetainInstance, the webclass fires the Terminate event only after it calls the ReleaseInstance method. See "State Management in IIS Applications" for more information about setting the StateManagement property.

There are no Load and Unload events for an IIS application. Instead, the BeginRequest or EndRequest events can perform some of the same functions as the Load and Unload event did — these events can be used to initialize values your application needs to run, and clean up state and other values at the end of a request. Begin and EndRequest are unique events for a webclass. A webclass may receive multiple requests throughout its life. These events allow the webclass to process each request as a unique entity.