ASP - List All Session Variables

home ~ tools ~ song quotes ~ podcast ~ song lyric trivia ~ docs ~ links ~ archives ~ search ~ lycii ~ mail
internetbumperstickers.com

List ASP Session Variables

Amended to include C#

This code will work for ASP 2.0 and 3.0 session variables but has not been updated for asp.net.

<% 

for each key in Session.Contents
  %><tr><%
  %><td><b style="COLOR: black; BACKGROUND-COLOR: #ffff66">Session</b>("<%=lcase (key)%>")</td><td><%
  if IsObject(Session.Contents(key)) then
    if lcase(TypeName(Session.Contents(key))) = "dictionary" then
      dumpDictionary(Session.Contents(key))
    else
      Response.Write TypeName(Session.Contents(key))
    end if
  else
    if IsArray(Session.Contents(key)) then
      %><ul><%
      for each n in Session.Contents(key)
        Response.Write ("<li>" & Session.Contents(key)(n))
      next
      %></ul><%
    else
      Response.Write ("<pre>" & Session.Contents(key) & "</pre>")
    end if
  end if
  %></td><%
  %></tr><%
next

%>

C# - List all session variables in ASP.NET

When developing in classic ASP, I had a standard page that I could drop in a folder and then view in a browser and the page would list the names of all the session variables in the application and their current value. I recently was trying to do the same thing in C# with ASP.NET.

I did the page with a codefile. There is nothing in the aspx page and just one thing in the pageload section.

for(int i=0;i<Session.Count;i++)
{
Response.Write("<p>" + Session.Keys[i].ToString() + " - " + Session[i].ToString() + "</p>");
}

I tried to keep it as simple as possible. There is no styling to the page, but it is for my eyes only, so my eyes are happy just to see all my session variables and their current values.