ASP implementation code for getting all session Variables

Source: Internet
Author: User

CopyCode The Code is as follows: dim strname, iloop
For each strname in session. Contents
Response. Write strname & "-" & session. Contents (strname) & "[br]"
Next

generally, the above Code works well. However, when the session variable is an object or array, the printed result is incorrect. The code is modified as follows: copy Code the code is as follows: 'First, check how many session variables are used?
response. write "there are" & session. contents. count & _
"session variables

"
dim strname, iloop
'Use for each to view the session. contents
'If the session variable is an array?
If isarray (Session (strname) Then
'print every element of the array cyclically
for iloop = lbound (Session (strname )) to ubound (Session (strname)
response. write strname & "(" & iloop & ")-" & _
SESSION (strname) (iloop) & "
"
next
else
'in other cases, the variable value is simply printed.
response. write strname & "-" & session. CONTENTS (strname) & "
"
end if
next

the session variable sometimes cannot work. Why? There are many possibilities: First, if the client does not allow cookie operations, the session will become invalid. Because session is dependent on cookies. Second, the session has an expiration time. The default value is 20 minutes. You can modify it like this: web directory-> properties-> virtual directory-> application settings-> Configuration-> app options-> Session Timeout or write the following code in ASP: session. timeout = 60. Third, the session is related to the specific web application. If you browse/jobs/default. asp from/products/default. asp, the session may be created again. How to clear a session variable that is no longer needed but does not make the session invalid? In asp3.0: Session. Contents. Remove "variable name" can clear a variable. In asp2.0, set session ("variable name") = NULL can clear variables. In asp3.0, session. Contents. removeall can clear all session variables, which are different from session. Abandon. The above method will not make the current session expire or invalid. What does ASP mean at the top of a page? IIS uses a technology called session tracking to ensure that each session variable is available on each page. When you access an ASP page, IIS will first prepare various session variables for the page, which of course will affect the performance. (The cost of using session variables is always high !) If you have 100 pages and only five pages use the session, you only need to set the following settings on the five pages: copy Code the code is as follows: <% @ enablesessionstate = true %>

other page settings: copy Code the code is as follows: <% @ enablesessionstate = false %>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.