ASP.NET Architecture, Part 2 - The Global.aspx.vb File
(Page 2 of 7 )
Although this ASP.NET server page does not allow for any user interaction, it does demonstrate browser-based application functionality in its most elementary form.
The Global.aspx.vb file contains information about the sequence of events and when they fire. The file begins by importing System.Web and the System.Web.SessionState. Public Class Global inherits the System.Web.HttpApplication class. After the InitializeComponent() method performs its task and allows for any other initialization, several events fire. The first event is the Application_Start method. The next event, Session_Start, fires, followed by the Application_BeginRequest method, which fires at the beginning of each subsequent request. Then the Application_AuthenticateRequest method fires. Other methods include Application_Authentication, Application_Error, Session_End, and Application_End. Here is the Global.aspx.vb file:
Imports System
.Web
Imports System.Web.SessionState
Public Class Global
Inherits System.Web.HttpApplication
#Region " Component Designer Generated Code "
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Component
'Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
#End Region
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
'Fires when the application is started
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
'Fires when the session is started
End Sub
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
'Fires at the beginning of each request
End Sub
Sub Application_AuthenticateRequest
(ByVal sender As Object, ByVal e As EventArgs)
'Fires upon attempting to authenticate the user
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
'Fires when an error occurs
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
'Fires when the session ends
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
'Fires when the application ends
End Sub
End Class
The lesson learned from examining this file is that the ASP.NET execution works entirely differently from classic ASP pages. Every .aspx page is automatically converted to a class and subsequently compiled to an assembly the first time it is accessed by a client. Expect some latency (delay) from this scenario.
When the user accesses the page, the generated assembly executes and creates an instance of that page. The page object provides a method for each event and generates output that is ultimately sent to the client’s browser.
This has been part two of ASP.NET Architecture (see part 1 here), chapter six of .NET & J2EE Interoperability, by Dwight Peltzer (McGraw-Hill/Osborne, ISBN 0-07-223054-1, 2004).
Buy this book now. |
Next: Creating a Web Form >>
More ASP.NET Articles
More By McGraw-Hill/Osborne