ASP. NET global. asax File

Source: Internet
Author: User

ASP. NET allows us to write event processors that can accept global events in the global. asax file. Instead of directly requesting the global. asax file, the user automatically executes the global. asax file in response to a specific application event. The global. asax file provides services similar to the Global. Asa file in traditional ASP applications.

In global. the code written in the asax file is similar to the webform code, but the difference is global. the asax file does not contain any HTML or ASP.. Net label. On the contrary, it contains some specific predefined methods. For example, the following example defines an event processor in the global. asax file to intercept the httpapplication. endrequest event. This event occurs before the webpage is sent to the user.

<% @ Application language = "C #" %>
<Script language = "C #" runat = "server">
Protected void application_onendrequest ()
{
Response. Write ("<HR/> This page was served at" +
Datetime. Now. tostring ());
}
</SCRIPT>
Even in global. the asax file is not specified, but global. all methods defined in the asax file are put into a separate application class. The application class inherits the httpapplication class, in the custom code, you can access all public and protected members in the httpapplication class. In the above example, the response object is used (the httpapplication class provides built-in attributes ).

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.