Page 233 - DCAP408_WEB_PROGRAMMING
P. 233

Unit 9: ASP Objects




                                                                                                Notes

              Task  Set the Session variable whose username is “Sonali Bose” and the Session variable
             age to “26”

          Loop Through the StaticObjects Collection

          You can loop through the StaticObjects collection, to see the values of all objects stored in the
          Session object:
          <%
          dim  i
          For  Each  i  in  Session.StaticObjects
              Response.Write(i  &  “<br  />”)
          Next
          %>

          Pitfalls of Session Variables

              Session variables and cookies are synonymous. So if a user has set his browser not to
               accept any cookies, your Session variables won’t work for that particular web surfer.
              An instance of each session variable is created when a user visits the page, and  these
               variables persist for 20 minutes AFTER the user leaves the page! (Actually, these variables
               persist until they “timeout”. This timeout length is set by the web server administrator. I
               have seen sites that the variables will collapse in as little as 3 minutes, and others that
               persist for 10, and still others that persist for the default 20 minutes. ) So, if you put any
               large objects in the Session (such as ADO recordsets, connections, etc.), you are asking for
               serious trouble! As the number of visitors increase, your server will experience dramatic
               performance woes by placing large objects in the Session.

              Since Session variables can be created on the fly, used whenever, and do not require the
               developer to dispose of them explicitly, the overuse of Session variables can lead to very
               unreadable and unmaintainable code.
              Session variables take you one step closer to VB programming in the sense that you can grab
               one without initializing the variable, use it whenever you want to, and not have to worry
               about releasing it when you’ve finished using it. And WHO wants to go there? Not me.

          Session Variable Cookies

          Kind  of. Session variables are bits of information that can be stored on a user-by-user basis.
          These bits of information are stored on the Web server. To tie these  bits of memory with a
          particular user, for session variables to persist across Web pages, the user must have cookies
          enabled. When a user first visits a page on a site that uses Session variables, two things happen:
          — A block of memory is allocated for that particular user’s session variables on the Web server.
          This block of memory is identified by a unique SessionID — A cookie is written to the user’s
          computer, storing the value of the SessionID
          When the user visits another page on the site that uses session variables, the users SessionID
          cookie is referenced to determine if the user already has a session variable memory block setup.
          If he does, the values that are stored there are referenced. Through this mechanism, one can
          create seemingly “global” variables that persist from one page to another.


                                           LOVELY PROFESSIONAL UNIVERSITY                                   227
   228   229   230   231   232   233   234   235   236   237   238