You want to make certain data available to all users of an application.
Place the code needed to find and load the data in the
Application_Start method of global.asax and store it in the
In the global.asax file, use the .NET language of your choice to:
Create an event handler for the
Load the application data and store it in the
The code we’ve written to demonstrate this solution is shown in Examples 7-1, 7-2, 7-3, 7-4, 7-5, 7-6 through 7-7. Examples 7-1 and 7-2 show the VB and C# global.asax files; this code reads data from a database and places it in the
Application object. Examples 7-3 and 7-4 show the VB and C# classes for constants used throughout the application to access the data in the
Application object. Figure 7-1 shows a simple form we’ve created to view the application state data. Example 7-5 shows the .aspx file that produces the form. Examples 7-6 and 7-7 show the companion VB and C# code-behind files that demonstrate how to access the application state data.
Figure 7-1. A view of some sample application state data
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 ...