I’m using SQL server session state.
If I’m using a master page that’s calling a few variables stored in the session, and then again use the session later in the aspx code behind, does this trigger:
a) 2 database reads, 1 during the master page process and a second one when the aspx runs.
b) 1 database read, the session is loaded during the master page process and persists during the life cycle of the page.
Thanks.
Master pages are user-controls attached to a page, and treated as such. As such, this question applies not just to Master Pages, but to all user controls, custom controls, and standard controls attached to a page.
SQL Servers stored session state is serialized/deserialized into/from the SQL Server on request. This is not a request of the variable but rather the HTTP request itself.
In the page lifecycle, the values are retrieved in the AcquireRequestState event, and pushed in the ReleaseRequesteState. These events are aspects ofthe HttpModule system, and as such are inherited by the Page class.
So, to answer your question, there is just a single call at the beginning of the page’s life cycle (before INIT) to the SQL Server to get the entire set of session variables regardless of how many variables you have in Session State. Then at the end of the page’s life cycle (and this is after RENDER & UNLOAD) there’s a second database call to store the session state