In program debugging, sometimes you need to know how many session variables are used

xiaoxiao2021-04-06  269

In program debugging, sometimes you need to know how many session variables are used, what is their value? Since the session object provides a collection called Contents, we can achieve your goals through the for ... EACH loop.

How to get all the session variables?

In program debugging, sometimes you need to know how many session variables are used, what is their value? Since the session object provides a collection called Contents, we can get the goal through the for ... EACH loop:

DIM STRNAME, ILOOP

For Each Strname in Session.Contents

Response.Write Strname & "-" & session.contents (strname) & "
"

NEXT

Under normal circumstances, the above code can work very well. But when the session variable is an object or array, the result of printing is not correct.

This way we modify the code as follows:

'' First look at how many session variables are used?

Response.write "There Are" & session.contents.count & _

"Session Variables

"

DIM STRNAME, ILOOP

'' Use for Each Cycling to see Session.Contents

'' If the session variable is an array?

IF isarray (session (strname) then

'' Cyclic print array of each element

For iLoop = lbound (session (Strname) to Ubound (session (Strname)

Response.Write Strname & "(" & iLoop & ") -" & _

Session (Strname) & "
"

NEXT

Else

'' Other situations, the value of simple print variables

Response.Write Strname & "-" & session.contents (strname) & "
"

END IF

NEXT

The session variable is sometimes can't work, why? There are many possibilities: First, if the client does not allow cookie operations, the session will be invalid. Because session depends on cookie. Second, session has the setting of failure time. The default setting is 20 minutes. You can modify it this: Web Directory -> Properties -> Virtual Directory -> Application Settings -> Configuration -> App Options -> Session Timeout or in ASP, write this code: session.timeout = 60. Third, Session is related to the specific web application. If the user browses to /jobs/default.asp from /products/default.asp, it may also cause recreate of session.

How to clear a session variable that is no longer need but does not make session? In ASP3.0: session.contents.remove "Variable Name" can clear a variable. In ASP2.0: SET Session ("Variable Name) = NULL can clear the variable. In ASP3.0, session.contents.removell can clear all session.abandon, the above method does not expire or invalidate the current session. <% @ EnableSessionState = true%> What is the top of the ASP page? IIS uses a technology called session tracking to ensure that each session variable is available in each page. When the user accesses an ASP page, IIS will first prepare each session variable for this page, which of course will bring performance. (The price of the session variable is always very high!) If you have 100 pages, only 5 pages have been used as SESSION, then for the overall performance, you only need to set up the 5 page settings: <% @ enablessionState = True%> and other pages set to: <% @ enablessionState = false%>

转载请注明原文地址:https://www.9cbs.com/read-132298.html

New Post(0)