This is a mirror of official site: http://jasper-net.blogspot.com/

ASP.NET Internals : “Clearing ASP.NET Session Variables” a in-depth look

| Tuesday, August 2, 2011
ASP.NET Session is one of most common state management technique for any ASP.NET Web Application.  If you want to do a quick refresh or want to know some thing more, please go ahead and read one of my article “Exploring Session in ASP.NET” published at Code Project.  ASP.NET provides several methods for removing Session. But which methods needs to use at what time, is a must known stuff for asp.net developer. In this post I going to talk about bit internals of removing session variables from applications. Why this Post ?  I found many people having some confusion around removing / clearing the  session variable ( Mainly with Session.Clear(), Session.RemoveAll(), Session.Abandon()) , which method needs to use, what is the purpose of particular method etc.

ASP.NET Provides below methods to clearing or removing Session information.

    Session.Clear()
    Session.RemoveAll()
    Session.Abandon()
    Session.RemoveAt(index)
    Session.Remove(string);

We will be mainly focusing the first 3 methods.

Let’s start with Session.Clear() and Session.RemoveAll(). Well, you may ask, why I am starting with two methods together. Yes, we are in same track. Both Session.Clear() and Session.RemoveAll() does the same job. Let’s explore it

Session.Clear () Vs. Session.RemoveAll()

Let’s assume  stored below information with in session variable.

image.png?w=375&h=115
now, if you want to remove all the items from session you can use either Session.RemoveAll() or Session.Clear().   if you check the definition  from meta data file you will get below details, where description says the same.


Read more: Beyond Relational
QR: asp-net-internals-clearing-asp-net-session-variables-a-in-depth-look.aspx

Posted via email from Jasper-net

0 comments: