?
Solved

Iterate through all values of HttpSessionState collection

Posted on 2008-02-03
4
Medium Priority
?
946 Views
Last Modified: 2008-02-20
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

0
Comment
Question by:bobinorlando
  • 2
  • 2
4 Comments
 
LVL 29

Expert Comment

by:QPR
ID: 20809677
SessionColl.GetEnumerator()

Should this be Session.GetEnumerator()
0
 
LVL 29

Accepted Solution

by:
QPR earned 1500 total points
ID: 20809683
0
 
LVL 2

Expert Comment

by:fredmastro
ID: 20810317
You can use this...

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

Open in new window

0
 
LVL 2

Expert Comment

by:fredmastro
ID: 20810319
       For Each Key As String In Session.Keys
            Response.Write(Key & " = " & Session(Key).ToString & "<br />")
        Next
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
There is a wide range of advantages associated with the use of ASP.NET. This is why this programming framework is used to create excellent enterprise-class websites, technologies, and web applications.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Suggested Courses
Course of the Month6 days, 16 hours left to enroll

594 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question