views:

50

answers:

3

I have a class called Global that derives from HttpApplication.

Oddly, I see a lot of methods inside Global that look like:

void Application_Start(object sender, EventArgs e)
{
}

The code is definitely executing inside this method, so the method is being called from somewhere, but where? The methods aren't marked overload?

Secondly, I derived a class from Global, let's call it GlobalFoo.

Again, if I create a method called Application_Start() it will get called inside my derived class, otherwise nothing that's in Global will get called so I might as well be deriving from an empty class.

Can anyone offer any advice? Am I missing some fundamental part of ASP.NET?

A: 

The Global.asax file is an optional file used to declare and handle application and session-level events and objects for an ASP.NET web site running on an IIS Web Server

some of the key events in this file are:

  • Application_Init: Fires when the application initializes for the first time.
  • Application_Start: Fires the first time an application starts.
  • Session_Start: Fires the first time when a user’s session is started.
  • Application_BeginRequest: Fires each time a new request comes in.
  • Application_EndRequest: Fires when the application terminates.
  • Application_AuthenticateRequest: Indicates that a request is ready to be authenticated.
  • Application_Error: Fires when an unhandled error occurs within the application.
  • Session_End: Fires whenever a single user Session ends or times out.
  • Application_End: Fires when the application ends or times out (Typically used for application cleanup logic).

For a complete list of Global.asax events see "Global.asax Events".

Bobby Borszich
I don't really care about the events themselves, Im confused over where / how they're being called
maxp
A: 

IIS calls the different Global.asax events through the asp.net isapi filter.

Perhaps this article will help explain.

Oded
+1  A: 

so the method is being called from somewhere, but where?

This functions are called from the Application Pool (from each pool that you have assign), to signal start-up/end events of your application and help your with initializations.

Every pool that is assign to run your web application runs those functions.

asp.net is helping you create different objects/code external or not that can run together, and that's why you see that all of your registered code run. Its a help to create more than one "start up" routines that do different thinks.

This is an example, this module just check the secure protocol by him self... and you do not need to change anything on your code, just register it.

Aristos