ASP Getting Started tutorial-identifying sessions with session objects

Source: Internet
Author: User
Tags sessions

1, what is the session identification

ASP assigns a unique identification flag to each user session. When you create a session, the server generates a separate identity for each session, which is returned with a long integer data type and is saved with the user on the Web site. Use the SessionID property of the Session object to return the user's conversation identity in the following format:

Session.SessionID

One use of the SessionID property is to track the activity of the visitor. For example, to record a user-visited page in the site log, add the following script to all pages:.

2. Instance code (4.asp): This example uses the SessionID property of the Session object to display the user's conversation identity, using the script_name of the server variable to obtain the current path of the user to access the Response object AppendToLog Method adds a string to the requested Web site log file, which consists of two parts: the 1th part is the session identity, and part 2nd is the current page path. and write a simple counter program through the session collection.

<body>
<%
who = Session.SessionID
CurrentPage=Request.ServerVariables("SCRIPT_NAME")
Response.AppendTolog who & ":" & CurrentPage
Response.write "<center>你的会话标识为:" & who & "<p>"
Response.write "你当前访问的页面路径为:" & CurrentPage & "<p>"
if Session("I")="" then
session("i")=1
else
session("i")=session("i")+1
end if
Response.write "本页面被你刷新了" & Session("i") & "次。</centr>"
%>

4, the Code annotation

Open IE browser window, and then in the Address bar to enter the URL of the above page, and press F5 key to refresh the page, then open an IE browser window, and then in the Address bar to enter the page URL, and continuously press F5 key Refresh page. At this point, you see two different session identities appearing in two windows, the session identity in each window is unchanged when the page is refreshed, and the number of page refreshes in two windows is independent of each other.

5. Note: The site log file is stored in WINNTSYSTEM32LOGFILESW3SVC1, which is a set of text files with a. log extension.

See the full set of ASP Getting started tutorials

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.