Session. Abandon (delete the session object after the current page ends) Session. Clear (clear the content in the session object)

Source: Internet
Author: User

Abandon

The abandon method deletes all objects stored in the session object and releases the source of these objects. If you do not explicitly call the abandon method, the server will delete these objects once the session times out.

Syntax

Session. Abandon

Note

When the abandon method is called, the current session object will be deleted in sequence. However, after all script commands on the current page are processed, the object will be deleted.

This means that when you call abandon, you can access the variables stored in the session object on the current page, but not on subsequent web pages.

For example, in the following script, the third line prints the Mary value. This is because the session object is not deleted before the server completes processing the script.

<%

Session. Abandon

Session ("myname") = "Mary"

Reponse. Write (Session ("myname "))

%>

 

If you access the myname variable on the subsequent web page, you will find it empty. This is because when the page containing the previous example ends processing, myname is deleted along with the previous session object.

When a session is abandoned and a web page is opened, the server creates a new session object. You can store variables and objects in the new session object.

Example

When the server finishes processing the current page, the following example releases the session status.

<% Session. Abandon %>

Clear

What is the difference between session. Abandon and session. Clear?

Session. Clear () is to delete all the items in the session object, and there is nothing in the session object.However, the session object is retained.
.

Session. Abandon () is to delete the current session object, and the next session is the new session.

The main difference is:

When session. Abandon is used, the session_end method is called (in inproc mode ). When the next request arrives, the session_start method is triggered. session. Clear only clears all data in the session and does not stop the session. Therefore, it does not call those methods.

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.