Link to home
Start Free TrialLog in
Avatar of bobinorlando
bobinorlando

asked on

Iterate through all values of HttpSessionState collection

How do I iterate through all values of httpsessionstate collection and display them on a page?
Thanks in advance.

I tried this without luck.

'Adapted from MSDN on Collectionbase class

 Public Sub PrintIndexAndValues(ByVal SessionColl As HttpSessionState)
        Dim i As Integer = 0
        Dim myEnumerator As System.Collections.IEnumerator = SessionColl.GetEnumerator()
        While myEnumerator.MoveNext()
            Response.Output.Write("   [{0}]:   {1}", i, myEnumerator.Current)
            i += 1
        End While
   End Sub 'PrintIndexAndValues

which I then call from PageLoad

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

        'Show the Session ID
        lblSessionID.Text = "Your SessionID = " & Session.SessionID 'This shows

        PrintIndexAndValues(Session) 'This does not show

        Response.Output.Write("abcd") 'This shows
    End Sub

Avatar of QPR
QPR
Flag of New Zealand image

SessionColl.GetEnumerator()

Should this be Session.GetEnumerator()
ASKER CERTIFIED SOLUTION
Avatar of QPR
QPR
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can use this...

        For Each Key As String In Session.Keys
            Response.Write(Key & " = " & Session(Key).ToString & "<br />")
        Next

Open in new window

       For Each Key As String In Session.Keys
            Response.Write(Key & " = " & Session(Key).ToString & "<br />")
        Next