How are Application_Start, etc., called?

  • Thread starter Harlan Messinger
  • Start date
H

Harlan Messinger

How do the Application methods like

protected void Application_Start

get called? They aren't base class overrides and they aren't
implementing interface methods. What mechanism does the system use to
call them?

In a Web form, a similar handler like

private void Page_Load

gets called by virtue of the fact that the following line appears later
on in the page, in the OnInit override:

this.Load += new System.EventHandler(this.Page_Load);

But there isn't anything comparable in Global.asax.
 
R

Robbe Morris [C# MVP]

They are events and they are wired up internally in ASP.NET
when the request is processed, session starts, or application
starts.
 
L

Laurent Bugnion

Hi,

Could you avoid top posting? It makes the posts very difficult to read.

> Does it matter> Is it not enough to know that they are fired?

It does matter if you want to hook your own event handlers, for example.
It also matters if you want to have a deep understanding of how ASP.NET
works.

HTH,
Laurent
 
L

Laurent Bugnion

Hi,

Harlan said:
How do the Application methods like

protected void Application_Start

get called? They aren't base class overrides and they aren't
implementing interface methods. What mechanism does the system use to
call them?

In a Web form, a similar handler like

private void Page_Load

gets called by virtue of the fact that the following line appears later
on in the page, in the OnInit override:

this.Load += new System.EventHandler(this.Page_Load);

But there isn't anything comparable in Global.asax.

The Global.asax only defines the event handlers' body, not how they are
fired. The method Application_Start is the equivalent of the Page_Load
in the line you wrote here above. The "hook" to the "Start" event (which
is the equivalent of the "Load" event in the line here above) is not
defined in Global.asax. The methods are called at various moments by the
different modules involved in processing the request.

There is an interesting post about this at
http://www.dotnet247.com/247reference/msgs/12/62243.aspx

HTH,
Laurent
 
H

Harlan Messinger

> Does it matter> Is it not enough to know that they are fired?

In case you're not aware of it, there are people in this world who are
curious about how things work. You should be thankful for that. Think
how the world would be otherwise.
 
H

Harlan Messinger

Laurent said:
Hi,



The Global.asax only defines the event handlers' body, not how they are
fired. The method Application_Start is the equivalent of the Page_Load
in the line you wrote here above. The "hook" to the "Start" event (which
is the equivalent of the "Load" event in the line here above) is not
defined in Global.asax.

Right, that's the part that I wasn't expecting.
The methods are called at various moments by the
different modules involved in processing the request.

I was just curious *how*, since there isn't an interface or base class
through which they could be doing that. It's occurring to me that it
must be through reflection, which seems sloppy and unnecessary, but
maybe the aspnet really handles the whole creation of the application
class object at that low level.

Thanks for that interesting overview.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top