Run code for every Page_Load?

  • Thread starter Thread starter Olav Tollefsen
  • Start date Start date
O

Olav Tollefsen

I would like some common code to be executed before Page_Load is called for
every Web Form page. The code should do some logging.

Where can I put common code like this? I would like to avoid having to
manually insert the code on every page in my application.

Olav
 
You run it in Application_Start or Session_Start depending
on it's common to application or seesion.

HTH

Elton Wang
(e-mail address removed)
 
Thanks for the hint. I think found the answer:

I guess the correct way is to create an Application_BeginRequest function in
Global.asax?

Olav
 
I tested adding a Application_BeginRequest in Global.asax and it got called
multiple times for every load of a web page.

Is this normal?

Olav
 
Another alternative is to create your own page class that inherits from Page
and all your pages derive from this new class. Then you can override the
OnLoad method.
 
Hi Olav
create a class and put int it subMAin and put all code on it
then make this the ur start page
Hope this help
 
Back
Top