Results 1 to 2 of 2

Thread: [2005] Session and Cookies

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    240

    [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!

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width