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 ).