I want to store something in the Session object (i.e. a user ID), before anything else happens in a Page’s Life Cycle.
I tried putting it in the Page’s constructor, but the Session object isn’t yet available then.
I tried overriding OnInit, but then other delegates hooked to the Init event might still be executed prior.
I’m really lost, even though this feels like very basic ASP.NET theory.
A more usual approach is to encapsulate access to the data in Session, and load it on demand the first time it’s accessed. The basic pattern looks like the following:
In this way the data will be loaded the first time it’s needed, and you don’t need to care when that is in the page lifecycle.