Usage Analysis of the Global program file Global. asax in ASP.net, asp. netglobal. asax

Source: Internet
Author: User

Usage Analysis of the Global program file Global. asax in ASP.net, asp. netglobal. asax

This article details the usage of the Global. asax Global program file of ASP.net and shares it with you for your reference. The specific analysis is as follows:

Generally, an ASP. NET application can have only one Global. asax file, which supports many items. The specific analysis is as follows:

• Application_Start: called when the application receives the first request, which is an ideal place for assigning values to application-level variables in the application or specifying the State that must be maintained for all users.

• Session_Start: similar to the Application_Start event, which is called when the user first accesses the application. For example, the Application_Start event is triggered only when the first request is received. The first request allows the application to run, and the Session_Start event is called when each end user sends a request to the application for the first time.

• Application_BeginRequest: it is not listed in the template provided by Visual Studio, but this event is triggered before each request is sent. That is, the Application_BeginRequest event is triggered and processed before the request arrives at the server.

• Application_AuthenticateRequest: this event is triggered for each request, allowing custom authentication for the request.

• Application_Error: triggered when the application user throws an error. It is suitable for providing application-level error handling, or recording errors into server Event Logs.

• Session_End: this event is triggered when the end user exits the application when running in InProc mode.

• Application_End: triggered when the application ends. Most ASP. NET developers do not use this event because ASP. NET does a good job of closing and clearing the remaining objects.

I hope this article will help you design your asp.net program.


How do I create a Globalasaxresx file in aspnet? What is the role?

The Global. asax file (also known as an ASP. NET application file) is an optional file that contains code used to respond to application-level events caused by ASP. NET or HttpModule. The Global. asax file resides in the root directory of ASP. NET-based applications. At runtime, analyze the Global. asax file and compile it into a dynamically generated. NET Framework class, which is derived from the base class of HttpApplication. The Global. asax file is configured to automatically reject any direct URL requests to it. external users cannot download or view the code written in the file.

The ASP. NET Global. asax file can coexist with the ASP Global. asax file. You can create Global in WYSIWYG designer or notepad. asax file, or create it as a compiled class and deploy the class as an assembly in the \ Bin directory of the application. However, in the following case, you still need a Global. asax file that references the assembly.

The Global. asax file is optional. If this file is not defined, the ASP. NET page framework assumes that you have not defined any applications or session event handlers.

When you save the changes to the active Global. asax file, the ASP. NET page framework detects that the file has been changed. It completes all the current requests of the application, sends the Application_OnEnd event to any listener, and restarts the application domain. In fact, this will restart the application, close all browser sessions, and refresh all status information. When the next incoming request from the browser arrives, the ASP. NET page framework will re-analyze and re-compile the Global. asax file and trigger the Application_OnStart event.

Similar to ASP, but more powerful.

How can I add a global application class to aspnet?

If you are using asp. net2.0, add an App_Code system folder to the project solution control panel and put your Global application class (such as Global. cs) in this folder! Assume that there is an integer in the class to convert the string as follows:
Public static string Int2Str (int I ){......}

You can call the following code in other code files (Default. aspx. cs!
String;
A = Global. Int2Str (23 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.