How to get all session variables

zhaozj2021-02-11  249

How to get all 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, ILOOPFOR EACH STRNAME IN Session.contentsResponse.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 see how many session variables are used?

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

" DIM STRNAME, iLOOP 'uses for Each cycle to see session.contents' If the session variable is an array? If isarray (session (Strname) 101 'cyclic print array for each element for iLoop = lbound (session (Strname) to Ubound ("& iLoop &") - "& _Session (Strname) ) & "
" NEXTELSE 'Other cases, the value of simple print variables Response.write strname & "" & session.contents (strname) & "
" end ifnext

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-4130.html

New Post(0)