19 January 2014

Session Add, Remove, Clear, RemoveAll and Abandon in ASP.NET

Session Add, Remove,  Clear, RemoveAll  and Abandon in ASP.NET

1. Session Add

To add in the Session
For ex
Session.Add("UserID",1);
   or
Session["UserID"]=1;

UserID is Session ID
1 is Session value

2. Session Remove

Session.Remove(“UserID”);
It removes the specific session’s specific key value i.e) It removes the SessionID UserID


3. Session Clear

Session.Clear()
It clears all session value i.e) It clears all the key value pairs stored in the session state collection.

4. Session RemoveAll

Session.RemoveAll();
This Method calls above clear method in its implementation,
public sealed class HttpSessionState : ICollection, IEnumerable
{
   .....
   public void RemoveAll()
   {
       this.Clear();
   }
   .....
}

5. Session Abandon

Session.Abandon() destroy everything in the session. While logout you have to clear everything in session.




No comments:

Post a Comment

Comments Welcome