I'm wondering if there's a way to automatically stub in the Global.asax's event handlers? Thus far, I've not been able to find any examples of how to do this. Seems I have to just find the list of delegate names available to me and type them in manually.
Intellisense doesn't seem to lend any useful info on the subject either.
In this article, we learnt that Global. asax is a file used to declare application-level events and objects. The file is responsible for handling higher-level application events such as Application_Start, Application_End, Session_Start, Session_End, and so on.
Application_BeginRequest: Fired when an application request is received. It is the first event fired for a request, which is often a page request (URL) that a user enters. Application_EndRequest: The last event fired for an application request.
Application_Error() – fired when an error occurs. Session_End() – fired when the session of a user ends. Application_End() – fired when the web application ends. Application_Disposed() - fired when the web application is destroyed.
The ASP.Net runtime uses reflection to dynamically look for methods with names like "Application_Start", "Session_Start" etc. and then binds them to the corresponding events on the HttpApplication class. You can effectively bind to any of the HttpApplication events simply by including a method in Global.asax.cs whose name is "Application_" followed by the name of the event. For example, to utilize the EndRequest event, add this to your Global.asax.cs file:
protected void Application_EndRequest(object sender, EventArgs e)
{
// Your code here
}
See this Blog Entry from Rick Strahl for a bunch of helpful information on how this is done.
All of the events of the HttpApplication
class can have a handler in the global.asax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With