Saturday, September 24, 2011

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 !!

No comments :

Post a Comment