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.