Advanced ASP Programming (8): built-in object Session

Source: Internet
Author: User
Tags session id sessions
In addition to the objects used for sending (Response), receiving and processing data (requeest), and Server access (Server), ASP objects also have some very useful Application tags) and the object of a single user information (Session.
Session object
This object accounts for a considerable proportion of ASP usage. A web page is a stateless program and cannot be viewed by users. In ASP, Session objects are used to record the user's private data variables, so as to confirm the user's request for the server again. When the user redirects between the Web pages of the program, variables in the Session object will not disappear.
These are really important functions, especially those that must be used by member systems. Such as the member's login account, time, status, and real-time data of many such records (for example, the shopping system records the items in the user's shopping basket). Such information is required by individual users, generally, developers use Session record processing.
Sessions in ASP are composed of Cookies. The server transmits the data recorded in all sessions to the user's browser as Cookies. Generally, browsers store these Cookies. When users click the link and connect to the Server again, the browser will send these Cookies back to the Server for processing: this is the principle of Session operation. It can be seen that Session state sessions are only retained in browsers that support cookies. If the client closes the cookie option Session, it will not be able to play a role.
I. Session. SessionID
The SessionID attribute returns the user's session id. When a session is created, the server generates a separate identifier for each session. The session identifier is returned as a long integer data type. In many cases, SessionID can be used for WEB page registration statistics.
This attribute can be used to solve a problem of user control. The main function of this problem is to view a module of a website. When a member logs on to this module and another user logs on with the same member name, the module cannot be viewed: that is to say, a member name can only be viewed by one person at the same time.
The member name (assumed as UserID, unique) and SessionID are used for control. When a member logs on, a Session is sent to the member to record the logon Status, for example, Session ("Status") = "Logged", and the Session. SessionID of the member is written to the database. When he wants to browse this module, he first checks whether he is logged on. If he has logged on, he checks whether his SessionID is the same as that recorded in the database. If not, he cannot access it.
In this way, when another user logs on with the same member name, the database records the new SessionID. The former cannot pass the check when accessing this module. This enables a single member name to be viewed by only one person at the same time. This feature has a special effect on some paid websites. It prevents a member name from being browsed by multiple users and safeguards the company's interests.
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.