sesión del servidor sql en la página maestra y en la página aspx

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.


preguntado el 28 de agosto de 11 a las 03:08

2 Respuestas

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

Respondido 28 ago 11, 07:08

ohh, btw, if I'm using the session in an http module that triggers before the requests even hit the aspx, does the principle of 1 request = 1 session read still hold? - frenchie

Yes. The AcquireRequestState and ReleaseRequestState events actually occur at the HTTP module level. - Stephen Wrighton

The reads will result in only 1, the session object is recreated from the store at the beginning of the request.

When a page saves data to Session, the value is loaded into a made-to-measure dictionary class hosted by the HttpSessionState class. The contents of the dictionary is flushed to the state provider when the ongoing request completes. If the session state is empty because no data has been programmatically placed in the dictionary, no data is serialized to the storage medium and, more importantly, no slot is created in either the ASP.NET Cache, SQL Server, or NT state service to track the current session. This is done for performance reasons but has a key repercussion on the way in which the session ID is handled: A new session ID is generated for each request until some data is stored in the session dictionary. - see para más detalles

Respondido 28 ago 11, 07:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.