Life cycle events and Global.asax files
During the life cycle of an application, an application raises an event that can be handled and invokes a specific method that can be overridden. To handle application events or methods, you can create a file named Global.asax in the application root directory.
If you create a Global.asax file, ASP. NET compiles it to a class that derives from the HttpApplication class and then uses that derived class to represent the application.
An instance of the httpapplication process processes only one request at a time. This simplifies the application's event-handling process because it does not need to be locked when accessing non-static members in an application class. This also allows the request-specific data to be stored in non-static members of the application class. For example, you can define a property in the Global.asax file, and then assign a request-specific value to the property.
By using a naming convention application_event(such as application_beginrequest), ASP. NET can be Global.asax The application event is automatically bound to the handler in the file. This is similar to the method of automatically binding an ASP. NET page method to an event, such as a page's Page_Load event. For more information, see the ASP. NET page life cycle Overview.
The Application_Start and application_end methods are special methods that do not represent HttpApplication events. During the life cycle of an application domain, ASP. NET calls these methods only once, not once for each HttpApplication instance.
1 The following events are executed by the HttpApplication class when the request is processed. Developers who want to extend the HttpApplication class need to be aware of these events in particular. 2 3 validation of the request checks the information sent by the browser and determines whether it contains potentially malicious tokens. For more information, see ValidateRequest and Scripting Intrusion Overview. 4 5 If any URLs have been configured in the Urlmappingssection section of the Web. config file, the URL mapping is performed. 6 7 raises the BeginRequest event. 8 9 raises the AuthenticateRequest event. Ten One raises the Postauthenticaterequest event. A - raises the AuthorizeRequest event. - the raises the Postauthorizerequest event. - - raises the Resolverequestcache event. - + raises the Postresolverequestcache event. - + depending on the file name extension of the requested resource (mapped in the application's configuration file), select the class that implements IHttpHandler to process the request. If the request is for an object (page) derived from the page class, and the page needs to be compiled, ASP. NET compiles it before creating an instance of the page. A at raises the Postmaprequesthandler event. - - raises the AcquireRequestState event. - - raises the Postacquirerequeststate event. - in raises the PreRequestHandlerExecute event. - to call the appropriate IHttpHandler class's ProcessRequest method (or asynchronous version BeginProcessRequest) for the request. For example, if the request is for a page, the current page instance will process the request. + - raises the PostRequestHandlerExecute event. the * raises the ReleaseRequestState event. $ Panax Notoginseng raises the Postreleaserequeststate event. - the If the Filter property is defined, the response filter is executed. + A raises the Updaterequestcache event. the + raises the Postupdaterequestcache event. - $Raises the EndRequest event.
Application restarts (number of application restarts)
Modifying the source code of the WEB application will cause ASP. NET to recompile the source file into an assembly. When you modify a top-level item in an application, all other assemblies in your application that reference the top-level assembly are also recompiled.
In addition, modifying, adding, or removing certain types of files in the application's well-known folders will cause the application to restart. The following actions will cause the application to restart:
Add, modify, or delete an assembly in the application's Bin folder.
Add, modify, or delete localized resources in the App_GlobalResources or App_LocalResources folder.
Add, modify, or delete an application's Global.asax file.
Add, modify, or delete source code files in the App_Code directory.
Add, modify, or delete configuration file configurations.
Add, modify, or delete Web service references in the App_WebReferences directory.
Add, modify, or delete the Web. config file for your application.
When an application requires a restart, ASP. NET will service all pending requests from the existing application domain and from the old assembly before restarting the application domain and loading the new assembly.
Go ASP. Application Life Cycle Events