Page 232 - DCAP408_WEB_PROGRAMMING
P. 232

Web Programming




                    Notes          <%
                                   If  Session.Contents(“age”)<18  then
                                       Session.Contents.Remove(“sale”)
                                   End  If
                                   %>
                                   To  remove  all  variables  in  a  session,  use  the  RemoveAll  method:
                                   <%
                                   Session.Contents.RemoveAll()
                                   %>
                                   Loop Through the Contents Collection

                                   The Contents  collection  contains  all session  variables. You  can loop through the  Contents
                                   collection, to see what’s stored in it:
                                   <%
                                   Session(“username”)=”Donald  Duck”
                                   Session(“age”)=50
                                   dim  i
                                   For  Each  i  in  Session.Contents
                                       Response.Write(i  &  “<br  />”)
                                   Next
                                   %>
                                   Result:
                                   Username
                                   Age
                                   If you  do not know the number of items in  the Contents collection, you  can use the  Count
                                   property:
                                   <%
                                   dim  i
                                   dim  j
                                   j=Session.Contents.Count
                                   Response.Write(“Session  variables:  “  &  j)
                                   For  i=1  to  j
                                       Response.Write(Session.Contents(i)  &  “<br  />”)
                                   Next
                                   %>
                                   Result:
                                   Session  variables:  2
                                   Donald  Duck
                                   50





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