Tutorials » AspNet tutorials »

Global events in ASP.NET


This article explains the Global.asax file and various events handled in Globa.asax file.


The following are the global events handled in the global.asax.vb file.



Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
End Sub


This event is fired when the application is started. The application starts when the first request comes to the web server after the IIS is started.

The Application start event can occur if the IIS is restarted, server rebooted, web.config file is changed or if the ASP.NET process recycles.

ASP.NET process recycles for various reasons like insufficient memory, server overload, other un expected errors etc.

This is the first event fired in ASP.NET after the application starts.


Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
End Sub


Session_Start event is fired each time a new session is started.


Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
End Sub


Application_BeginRequestis fired each time a new page is requested in the website. This event is fired after the Session_Start event.


Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
End Sub


Application_AuthenticateRequest is fired upon attempting to authenticate the user and after the Application_BeginRequest event.


Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
End Sub


If there is any unexpected error or un handled exception in the application, this event is fired. You can use this event to keep track of un expected errors in your web site and also to report such errors to the web master.

You will learn more about this event in the next chapter.


Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
End Sub


This event is fired when the session expires. Note that even if the user close the browser and leave, this event will not be fired immediately. Only after the session times out, the server will know that the user is no longer accessing the site and this event will be fired.

Session_End event will be fired if the application restarts.

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
End Sub


Application_End event is fired when the application ends like shutting down server, re starting IIS, recycling ASP.NET process etc.

Note that, if somebody power off the server, server will not get a chance to fire the events and this event will never be fired.



Next Chapter: Handling global errors in ASP.NET using Application_Error event
Previous Chapter: What is Global.asax file?
More Chapters: ASP.NET Tutorials
More Tutorials: Tutorial Index



Top Contributors
TodayLast 7 Daysmore...

Awards & Gifts

Online Members

More...
 
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India