Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all session info

Tags:

I want to display all the session information of my asp.net page (aspx) in the page. How can I do that?

The programming language is C#.

like image 726
Ricardo Felgueiras Avatar asked Apr 06 '10 11:04

Ricardo Felgueiras


People also ask

How can I get all sessions in PHP?

php session_start(); echo "<h3> PHP List All Session Variables</h3>"; foreach ($_SESSION as $key=>$val) echo $key." ".

Can I store list in session?

Yes, you can store any object (I assume you are using ASP.NET with default settings, which is in-process session state): Session["test"] = myList; You should cast it back to the original type for use: var list = (List<int>)Session["test"]; // list.


2 Answers

These two methods is working for me, improved and corrected David's answer slightly:

1st method

for (int i = 0; i < Session.Count; i++)
{
    var crntSession = Session.Keys[i];
    Response.Write(string.Concat(crntSession, "=", Session[crntSession]) + "<br />");
}

2nd method

foreach (var crntSession in Session)
{
    Response.Write(string.Concat(crntSession , "=", Session[crntSession .ToString()]) + "<br />");
}
like image 173
srn Avatar answered Oct 06 '22 02:10

srn


 foreach (string s in Session) {
        Response.Write(string.Concat(s, "=", Session[s]));
    }
like image 26
BlackICE Avatar answered Oct 06 '22 02:10

BlackICE