The Global.ASAX File
page 3 of 4
by . .
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 28426/ 49

Handling the Events
Handling the Events

Let's take a look at a sample Global.asax file -

<%@ Import Namespace="System.Diagnostics" %>
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
EventLog.WriteEntry("Sample Application", "Application Started!", EventLogEntryType.Information)
End Sub

Sub
Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Session.Contents.Add("TimeStart", DateTime.Now())
End Sub

Sub
Application_Error(ByVal sender As Object, ByVal e As EventArgs)
EventLog.WriteEntry("Sample Application", "Application Error Occured!", EventLogEntryType.Error)
End Sub

Sub
Application_End(ByVal sender As Object, ByVal e As EventArgs)
EventLog.WriteEntry("Sample Application", "Application Ended!", EventLogEntryType.Warning)
End
Sub
</script>

As you can see, this handles four events.

When the application starts or ends, it writes a semi-informative message to the system Event Log.
On an error, it writes an almost-useless message to the EventLog.
When a session begins (basically whenever someone visits the site) it adds a new session variable with the time they logged in (possibly a waste of session space).

Notice how it looks almost like a normal ASP.NET page, but without the HTML content.

ASP.NET will automatically compile and process this file.


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 12:48:04 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search