There are various ways to do this, but there are two recommended methods depending on if you need access to session state or not.
If you do NOT need session state, you use an init processor.
If you DO need session state, you use a state processor.
See Understanding Init Processors for details on init processors.
See Understanding State Processors for details on state processors.