Get list of all active session variables in ASP.NET

In this post I am going to discuss about  how you can get list of all active Session Variables in ASP.NET Application. The easiest way to get the details of session variable is using “Tracing” . If you enable the “Tracing” for your application, you can get list of all  Active Session variables. Another alternative way is, get all the list of session variable using “Session.Contents”.

To illustrate,  Let me store some dummy data to in some session variables,

image

Now, if you enable tracing in your page and inspect the Session State section, you will get the list of all session variable along with their type and values.

image

Now, if you want to read the same session variable programmatically, you have to use “Session.Contents”. Session.Contents returns the current System.Web.SessionState.HttpSessionState

image

 

Once done, you will get below details (here sessionItems is a multiline Text here )

image

Hope this will help you !!

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.