Friday, June 13, 2008

What method do you use to explicitly kill a user Session?

Ans : Session.Abandon
The Abandon method destroys all the objects stored in a Session object and releases their resources. If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.
Syntax Session.Abandon
When the Abandon method is called, the current Session object is queued for deletion, but is not actually deleted until all of the script commands on the current page have been processed. This means that you can access variables stored in the Session object on the same page as the call to Abandon, but not in any subsequent Web pages.
For example, in the following script, the third line prints the value Mary. This is because the Session object is not destroyed until the server has finished processing the script.
<% Session.Abandon Session("MyName") = "Mary" Reponse.Write(Session("MyName")) %>
The Remove method deletes a specific item from the Session object's Contents collection.
Session.Contents.Remove( Item|Index )
Item - The name of the member to remove from the collection.
Index - The index entry for the member to remove from the collection.
The Contents.Remove method takes either a string or an integer as an input parameter. If the input parameter is a string, the method will search the contents collection for an item with that name and remove it. If the input parameter is an integer, the method counts that number of items from the start of the collection, and removes the corresponding item.
The following example adds and removes a variable called myName to the Session.Contents collection.
<% Session("myName") = " " Session.Contents.Remove("myName") %>
The RemoveAll method deletes all items that have been added to the Session object's Contents collection.
Session.Contents.RemoveAll ()
The following example removes all items that have been added to the Session.contents collection:

No comments: