Author: Unknown Please click here to contact me
Global.asax file
In addition to writing the UI code, developers can also add the logic and event processing code of the application level to their web application. This code does not process the generation of the UI and is generally not called to respond to individual page requests. Instead, it is responsible for handling higher-level application events, such as Application_Start, Application_END, SESSION_START, SESSION_END, and more. Developers use the Global.asax files located at a specific web application virtual directory tree root to create this logic. When any resource or URL is activated or requested by the application namespace, ASP.NET automatically analyzes the file and compiles it into a dynamic .NET framework class (this class extends the httpApplication base class).
When you activate or request any resource or URL within the application namespace, ASP.NET analyzes the Global.asax file and dynamically compiles it into a .NET framework class. The global.asax file is configured to automatically reject any direct URL request, so that external users cannot download or view internal code.
Events within the application or session
The developer can define the handler for the event definition of the HTTPApplication base class by creating a method of changing the name mode "Application_EventName (ApproPriTeeventArgumentSignature" in the global.asax file. E.g:
C #:
Void Application_Start (Object Sender, Eventargs E) {
// Application Startup Code Goes Here
}
script>
VB:
Sub Application_Start (Sender As Object, E AS Eventargs)
'Application Startup Code Goes Here
End Sub
script>
If the event processing code needs to import additional namespaces, you can use the @ import command in the .aspx page, as shown below:
<% @ Import namespace = "system.text"%>
First open the page, trigger the Start event of the application and session:
C #:
Void Application_Start (Object Sender, Eventargs E) {
// Application Startup Code Goes Here
}
Void session_start (Object Sender, Eventargs E) {
Response.write ("Session is starting ...
);
Session.Timeout = 1;
}
VB
Sub Application_Start (Sender As Object, E AS Eventargs)
'Application Startup Code Goes Here
End Sub
SUB Session_Start (Sender As Object, E AS Eventargs)
Response.write ("session is start ...
")
Session.Timeout = 1END SUB
BEGINREQUEST and EndRequest events are triggered for each request. When refreshing the page, only messages from the BeginRequest, EndRequest, and Page_Load methods are displayed. Note: By abandoning the current session (click "End this Session" button), a new session will be created and the session_start event will again.
Objects within the application or session
Static objects, .NET Framework class, and COM components can be defined in the global.asax file using object tags. The range can be AppInstance, Session or Application. The AppInstance range represents an instance of the object specific to HTTPApplication and does not share.