ASP built-in object details of the session object

Source: Internet
Author: User
Tags define array http request variables sessions variable time limit
session| Objects | built-in objects |

The session actually refers to the time when the visitor arrives from a particular homepage to the date of departure. Each visitor will get a session individually. In a Web application, when a user accesses the application, the session-type variable allows the user to share data in all pages of the Web application, and if another user accesses the Web application at the same time, he has his own session variable, However, two users cannot share information through session variables, and application type changes can enable multiple users of the site to share information across all pages.

1, SessionID Property

This property returns the unique flag for the current session and assigns a different number to each of the sessions.
I have been in the development process of the user control problem. It is to achieve the function of a website for a module, when a member is looking at this module after login, another person with the same member login, can not browse this module. That is to say, a member name can only be browsed by one person at a time. I achieved control by using the membership name (assumed to be userid, unique) and SessionID. When the member logs in, give this member a session record login status such as: Session ("Status") = "logged", at the same time the member's Session.SessionID written to the database. When he wants to browse this module, first determine whether it is logged in, if you have logged in again to determine whether its sessionid is the same as the database records, if different can not access. In this way, when another user logs in with the same member name, the database records the new SessionID, which cannot be checked when accessing the module. This realizes a member name and can only browse a module by one person at a time. This feature has a special role in a number of toll sites, it prevents a member name for many people to browse the problem, for the company to protect the interests.

  2, Timeout property

This property is used to define the time limit for user session objects. If the user does not refresh the page within the specified time, the session object terminates. Generally defaults to 20 minutes.

3, Abandon method

This method is the only method of the session object that clears the session object to eliminate the user's session object and frees up the resources it occupies. such as: <% Session.Abandon%>

  4, Session_OnStart and Session_OnEnd events

As with application, the Session_OnStart event is triggered every time an object's routines are started, and then the process of Session_OnStart events is run. That is, when the server receives an HTTP request for a URL in the application, it triggers the event and establishes a Session object. Similarly, this event must also be set in the Global.asa file.

When the Session.Abandon method is invoked or not refreshed during the timeout time, this triggers the Session_OnEnd event and executes the script inside. Session variables are associated with a particular user, and the session variable assigned to a user is completely independent of the other user's session variable and does not interact with each other.

One example of Session application:

As with application, an array defined as a session type can only use the entire array as an object, and the user cannot directly change the value of an element in the session array. To create an array of sessions, you first define an ordinary array, assign an initial value to each of its elements, and then define it as an array of sessions. Such as:
<%
Dim Array ()
Array=array ("Jeff", "Zhu", "male")
Session ("info") =array
Response.Write Session ("info") (0) & "-"
Response.Write Session ("Info") (1) & "-"
Response.Write Session ("Info") (2) & "<br>"
%>
<%
Array (0) = "June"
Array (1) = "Li"
Array (2) = "female"
Session ("info") =array
Response.Write Session ("info") (0) & "-"
Response.Write Session ("Info") (1) & "-"
Response.Write Session ("Info") (2) & "<br>"
%>
The output of the above program is:
Jeff-zhu-male
_____________
Jun-li-female



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.