6.1. Maintaining Information Needed by All Users of an Application
Problem
You want to make certain data available to all users of an application.
Solution
Place the code needed to find
and
load the data in the Application_Start method of
global.asax and store it in the
Application object.
In the code-behind class for global.asax, use
the .NET language of your choice to:
Create an event handler for the
Application_Startevent.Load the application data and store it in the
Applicationobject.
The code we’ve written to demonstrate this solution
is shown in Example 6-1 through Example 6-5. Example 6-1 and
Example 6-2 show the VB and C# code-behind files for
global.asax; this code reads data from a
database and places it in the Application object.
Figure 6-1 shows a simple form that
we’ve created to view the application state data.
Example 6-3 shows
the .aspx file that produces the form. Examples
Example 6-4 and Example 6-5 show
the companion VB and C# code-behind files that demonstrate how to
access the application state data.

Figure 6-1. A view of some sample application state data
Discussion
The purpose of the Application object
is to store information once that can be simultaneously shared with all users of the application without having to access it repeatedly from a database or some other data store. A simple example is when you want to store and then share the number of times an application ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access