ASP all the session variables get implementation code _ Application Tips

Source: Internet
Author: User
Copy Code code as follows:

Dim StrName, Iloop
For each strName in session.contents
Response.Write StrName & "-" & Session.Contents (StrName) & "[BR]"
Next


In general, the code above can work very well. However, when the session variable is an object or an array, the printed result is incorrect. So we modify the code as follows:
Copy Code code as follows:

' First look at how many session variables are in use?
Response.Write "There are" & Session.Contents.Count & _
"Session Variables<p>"
Dim StrName, Iloop
' Use for Each loop to see Session.Contents
' If the session variable is an array?
If IsArray (Session (StrName)) Then
' Circulate every element of a set of print
For iloop = LBound (Sessions (StrName)) to UBound (session (StrName))
Response.Write StrName & "(" & Iloop & ")-" & _
Session (StrName) (iloop) & "<BR>"
Next
Else
' Otherwise, simply print the value of the variable
Response.Write StrName & "-" & Session.Contents (strName) & "<BR>"
End If
Next

Session variables sometimes don't work, why? There are many possibilities: first, the session will fail if the client does not allow cookies to operate. Because the session is dependent on cookies. Second, the session has the expiration time setting. The default setting is 20 minutes. You can modify it this way: Web directory-> Properties-> Virtual directory-> application settings-> Configuration App O Ptions-> session timeout or in ASP, write this code: SESSION.TIMEOUT=60. Third, the session is related to the specific Web application. If a user browses from/products/default.asp to/jobs/default.asp, it can also cause a session to be recreated. How do I clear a session variable that is no longer needed but not invalidate the session? In ASP3.0: Session.Contents.Remove "variable name" to clear a variable. In ASP2.0: Set session ("Variable name") =null can clear a variable. In ASP3.0, Session.Contents.RemoveAll can clear all the session variables and Session.Abandon, and none of the above methods will invalidate or invalidate the current session. What does the top of the ASP page mean? IIS uses a technique called session tracking to ensure that each session variable is available on each page. When a user accesses an ASP page, IIS prepares the session variables for the page first, which, of course, has a performance impact. (The cost of using session variables is always high!) If you have 100 pages, and only 5 pages use the session, then, for overall performance, you only need to set up on those 5 pages:
Copy Code code as follows:

<%@ enablesessionstate=true%>

And the other pages are set to:
Copy Code code 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.