Overview ASP. NET page framework

Source: Internet
Author: User

The Global. asax file, sometimes called an ASP. NET application file, provides a method to respond to application-level or module-level events at a central location. You can use this file to implement application security and other tasks. The following describes how to use this file in application development.

Overview

Global. asax is located in the application root directory. Although Visual Studio. NET automatically inserts this file into all ASP. NET projects, it is actually an optional file. There is no problem with deleting it-of course you are not using it .. The asax file extension indicates that it is an application file, rather than an ASP. NET file that uses aspx.

The Global. asax file is configured as any URL-based direct HTTP request is automatically rejected, so users cannot download or view its content. The ASP. NET page framework can automatically identify any changes made to the Global. asax file. After Global. asax is changed, the ASP. NET page framework restarts the application, including closing all browser sessions, removing all status information, and restarting the application domain.

Programming

The Global. asax file inherits from the HttpApplication class. It maintains an HttpApplication Object pool and assigns the objects in the pool to the application as needed. The Global. asax file contains the following events:
◆ Application_Init: this event is triggered when an application is instantiated or called for the first time. All HttpApplication object instances are called.
◆ Application_Disposed: triggered before the application is destroyed. This is an ideal location for clearing previously used resources.
◆ Application_Error: this event is triggered when an unhandled exception is encountered in the application.
◆ Application_Start: this event is triggered when the first instance of the HttpApplication class is created. It allows you to create objects that can be accessed by all HttpApplication instances.
◆ Application_End: this event is triggered when the last instance of the HttpApplication class is destroyed. It is triggered only once during the lifecycle of an application.
◆ Application_BeginRequest: triggered when an application request is received. For a request, it is the first trigger event, and the request is generally a page request URL entered by the user ).
◆ Application_EndRequest: the last event requested by the application.
◆ Application_PreRequestHandlerExecute: this event is triggered before the ASP. NET page framework starts to execute Event Handlers such as pages or Web services.
◆ Application_PostRequestHandlerExecute: this event is triggered when an event handler is executed at the end of the ASP. NET page framework.
◆ Applcation_PreSendRequestHeaders: this event is triggered when an HTTP header is sent to the client browser in the ASP. NET page framework.
◆ Application_PreSendContent: this event is triggered when the ASP. NET page framework sends content to the client browser.
◆ Application_AcquireRequestState: this event is triggered when the ASP. NET page framework obtains the Session status related to the current request.
◆ Application_ReleaseRequestState: this event is triggered when all event handlers are executed on the ASP. NET page framework. This causes all status modules to save their current status data.
◆ Application_ResolveRequestCache: this event is triggered when an authorization request is completed in the ASP. NET page framework. It allows the cache module to provide services for requests from the cache, bypassing the execution of event handlers.
◆ Application_UpdateRequestCache: When the ASP. NET page framework executes the event processing program, this event is triggered, so that the cache module stores response data for use in response to subsequent requests.
◆ Application_AuthenticateRequest: this event is triggered when the security module establishes a valid identity for the current user. At this time, the user's creden。 will be verified.
◆ Application_AuthorizeRequest: this event is triggered when the security module confirms that a user can access the resource.
◆ Session_Start: this event is triggered when a new user accesses the Application Web site.
◆ Session_End: this event is triggered when a user's session times out, ends, or leaves the application Web site.

This event list seems to be scary, but these events may be very useful in different environments. A key issue with using these events is to know the order in which they are triggered. The Application_Init and Application_Start events are triggered once when the application is started for the first time. Similarly, Application_Disposed and Application_End events are triggered once upon application termination. In addition, session-based events Session_Start and Session_End are used only when the user enters and leaves the site.

Other events process application requests. These events are triggered in the following order:
◆ Application_BeginRequest
◆ Application_AuthenticateRequest
◆ Application_AuthorizeRequest
◆ Application_ResolveRequestCache
◆ Application_AcquireRequestState
◆ Application_PreRequestHandlerExecute
◆ Application_PreSendRequestHeaders
◆ Application_PreSendRequestContent

  1. Implementation of ASP. NET plug-in
  2. Overview ASP. NET Applications
  3. Introduction to ASP. NET 2.0 Data Binding
  4. ASP. NET prevents Java Script Injection attacks
  5. ASP. net mvc using T4

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.