Session management

J

Justin

Right now, I am managing session state through SQLServer (sessionState
mode="SQLServer").

Any time I am accessing session variable, I know there will be roundtrip
(server hosting the application code to the server hosting the session).

My question is if I am accessing the session variable 5 times in a function,
will this cause 5 roundtrips to the server? (of course you can store session
in a local variable and access that 5 times but I am just curious whether
ASP.NET caches that value). So will the following code cause 5 roundtrips
or 1 roundtrip?

void test()
{
int O = Session["Test"];
int K = Session["Test"];
int L = Session["Test"];
int M = Session["Test"];
int N = Session["Test"];
}

Thanks
 
G

Guest

That' depends on how efficiently you write your code. if you need a Session
value, you only need to get it one time:

int O = Session["Test"];
int K = O;
int L = O;
int M = O;
int N = O;

Hope that helps.
Peter
 
B

Brock Allen

If you've configured Session to live in SqlServer you incurr one round trip
prior to your page being executed to fetch all of your session. After your
page is done executing, you incurr another round trip to write out your session
back to SqlServer. You can reduce this to one round trip if you change the
<@Page RequiresSessionState %> attribute on your page directive.

-Brock
http://staff.develop.com/ballen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top