Application or Session-Scoped Events
Developers can define handlers for events of the HttpApplication base class by
authoring methods in the Global.asax file that conform to the naming pattern
"Application_EventName(AppropriateEventArgumentSignature)". For example:
<script language="VB" runat="server">
Sub Application_Start(Sender As Object, E As EventArgs)
' Application startup code goes here
End Sub
</script>
VB
If the event handling code needs to import additional namespaces, the @ import
directive can be used on an .aspx page, as follows:
<%@ Import Namespace="System.Text" %>
The following sample illustrates the lifetime of Application,
Session, and Request.
The first time the page is opened, the Start event is raised for the application and the session:
Sub Application_Start(Sender As Object, E As EventArgs)
' Application startup code goes here
End Sub
Sub Session_Start(Sender As Object, E As EventArgs)
Response.Write("Session is Starting...<br>")
Session.Timeout = 1
End Sub
VB
The BeginRequest and EndRequest events are raised on each request.
When the page is refreshed, only messages from BeginRequest, EndRequest, and
the Page_Load method will appear. Note that by abandoning the current
session (click the "End this session" button) a new session is created
and the Session_Start event is raised again.
Application or Session-Scoped Objects
Static objects, .NET Framework classes, and COM components all can be defined in
the Global.asax file using the object tag. The scope can be appinstance, session, or
application. The appinstance scope denotes that the object is specific to one
instance of HttpApplication and is not shared.
<object id="id" runat="server" class=".NET Framework class Name" scope="appinstance"/>
<object id="id" runat="server" progid="COM ProgID" scope="session"/>
<object id="id" runat="server" classid="COM ClassID" scope="application"/>
- ASP.NET Framework applications can define event handlers with application-wide
or session-wide scope in the Global.asax file.
- ASP.NET Framework applications can define objects with application-wide
or session-wide scope in the Global.asax file.
Copyright 2001 Microsoft Corporation. All rights reserved.