How to print out all the variables in the Session?

 Posted by Chikul on 12/23/2009 | Category: ASP.NET Interview questions | Views: 5845
Answer:

Yes, Using "Session.Keys" we can get all session variables

In VB.NET

Dim strSesVar as string
For Each strSesVar In Session.Keys
Response.Write(strSesVar + " : " + Session(strSesVar).ToString() + "<br>")
Next


In C#

foreach (string strSesVar in Session.Keys)
{
Response.Write(strSesVar + " : " + Session[strSesVar].ToString() + "<br>");
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response