In program debugging, sometimes I need to know how many session variables are used and what is their value? Since the Session object provides a collection called Contents, we can achieve the goal through the for ... Each loop
Dim Strname, Iloop
For Each Strname in Session.contents
Response.write Strname & - & Session.contents (Strname) & [br]
Next
Under normal circumstances, the above code can work well. But when the session variable is an object or an array, the results of the printing are incorrect. This way we modify the code as follows:
'First see how many session variables are used?
Response.write there are & session.contents.count & _
Session variables <p>
Dim Strname, Iloop
'Use for each to check session.contents
'If the session variable is an array?
If isarray (session (strname) then
'Each element of a circular print array
For Iloop = LBOUND (Session (StrName)) to ubound (Session (STRNAME))
Response.write Strname & (& Iloop &) - & _
Session (Strname) (Iloop) & <br>
Next
Else
'In other cases, just print the value of the variable simply
Response.write Strname & - & Session.contents (Strname) & <br>
End if
Next
SESSION variables sometimes cannot work, why? There are many possibilities: First, if the client does not allow cookies to operate, the session will fail. Because session relies on cookies. Second, the session has the setting of failure time. The default settings are 20 minutes. You can modify it like this: Web Diretory -> Properties-> Virtual Directory-> Application Settings-> Configuration-> App Options-> Session Time or write this code: Session.tim Eout = 60. Third, session is related to the specific Web Application. If the user browses from /products/default.asp to /jobs/default.asp, it may also cause the session re -creation. How to clear a Session variable that no longer needs, but does not make the session fail? In ASP3.0: Session.contents.remove variable names can be cleared to remove a variable. In ASP2.0: SET Session (variable name) = NULL to remove variables. In ASP3.0, session.contents.removeall can clear all session variables from session.abandon. The above methods will not make the current session or invalid. What does the top of the ASP page mean? IIS uses a technology called Session tracking to ensure that each Session variable is available on each page. When a user visits a certain ASP page, IIS will first prepare each session variable for this page, which will of course have performance effects. (The cost of using the session variable is always very high!) If you have 100 pages and only 5 pages are used for session, then for the overall performance, you only need to set it on that 5 pages:
< %@ ENABLESESSIONSTATE = TRUE %>
And other pages are set to:
< %@ ENABLESESSIONSTATE = false %>