Select the product you need help with
INFO: Application Instances, Application Events, and Application State in ASP.NETArticle ID: 312607 - View products that this article applies to. This article was previously published under Q312607 On This PageSUMMARY The ASP.NET HttpApplication object hides many complex concepts to simplify the programming
model. This article describes some of these complexities. In addition, this
article describes how ASP.NET handles compatibility issues with the classic
Microsoft Active Server Pages (ASP) Application object. This article is divided into the following sections: MORE INFORMATIONApplication Class and Application InstancesAn application class is defined in the Global.asax file. The code in Global.asax defines a new class that is derived from System.Web.HttpApplication. In the absence of a Global.asax file, the base class, HttpApplication, is used as the application class.The ASP.NET runtime creates as many instances of application classes as needed to process requests simultaneously. For most applications, this number is limited to the number of threads and remains in the range of 1 through 100, depending on the hardware, server load, configuration, and so on. Many requests reuse application instances, and a free list of application instances is kept during periods of reduced load. Application instances are used in a thread-safe manner, that is, one request at a time. This has important implications:
Use the following guidelines to access the application instance that is associated with the current request:
Application EventsThe lifetime of a request consists of a series of the application events (and some implicit steps that ASP.NET implements). These events are listed below in the order in which they are executed:
The following items can handle these events:
Note In most cases, the actual response is sent to the client after the application instance is finished with the response (which is after EndRequest). Application_OnStart and Application_OnEndASP.NET introduces the unique Application_OnStart and Application_OnEnd "events" for compatibility with classic ASP. These "events" are executed only once in the lifetime of an application and not for every application instance. Therefore, if you change non-static members in these methods, you affect only one application instance and not all instances. You can initialize one application instance either in the constructor or by overriding the Init method.Application_OnStart is a logical equivalent to the class constructor for the application class, but it offers one advantage: the code has access to the HttpContext for the first request to the application. Application StateApplication state is a global dictionary of late-bound objects, which classic ASP introduces to compensate for the absence of global variables in Microsoft Visual Basic Scripting Edition (VBScript). In ASP.NET, you can access application state through one of the following:
To access static application members from pages in Microsoft Visual C# .NET and Microsoft Visual Basic .NET, you must use the ClassName attribute in Global.asax to name your application class. For example: PropertiesArticle ID: 312607 - Last Review: January 21, 2004 - Revision: 5.3
| Article Translations |


Back to the top








