Session problems

Source: Internet
Author: User
How to obtain all Session variables?
During program debugging, you sometimes need to know how many Session variables are in use and what are their values? 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
In general, the above code can work well. However, when the Session variable is an object or array, the printed result is incorrect.
The code is modified as follows:
''First, how many Session variables are used?
Response. Write "There are" & Session. Contents. Count &_
"Session variables <P>"
Dim strName, iLoop
''Use the For Each loop to view 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) & "<BR>"
Next
Else
''In other cases, the variable value is simply printed.
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 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"
You can clear a variable.
In ASP2.0:
Set session ("variable name") = NULL
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.