[2005] Session and Cookies
Some of my colleagues told me that session consumes lots of memory to the server.
What must I do to effectively used my sessions with minimal consumptions of memory in the server?
Can I pass the data from my sessions to a global variable so that it will not consumes lots of memory in the server?
ex.
after reading my session:
Code:
string username = (string)Session["username"];
if (username == null || username.Length == 0)
{
Response.Redirect("~/Default.aspx");
}
can I do this so that my other pages can also redirect to the default page if the session["username"] has no value:
Code:
GlobalVariable.username = (string)Session["username"];
so that instead of using the above code, I am going to do this:
Code:
if (GlobalVariable.username == null)
{
Response.Redirect("~/Default.aspx");
}
Thank you all!
Re: [2005] Session and Cookies
Unfortunately, your colleagues are not entirely correct.
While sessions do consume memory on the server, it's usually within acceptable limits. Provided you don't store too much pointless information in sessions.
Keep the data you store short and necessary. And keep in mind that sessions are destroyed after 20 minutes of non-use, by default. So you're pretty much safe.
Also, do not store username in a global variable. That is just stupid. It's things like usernames that are the reason Session variables were created!