Jelle De Loecker
Jelle De Loecker

Reputation: 21985

Print all session/post/get variables in ASP.NET page

I am very new to ASP.NET, I'm quite used to PHP (which we unfortunately do not use at work) I'd like to print all the session variables. In PHP it's quite easy, I use:

echo '<pre>' . print_r($_SESSION, true) . '</pre>';

for this, but is there an as-easy ASP.NET equivalent?

Upvotes: 5

Views: 8995

Answers (3)

corymathews
corymathews

Reputation: 12619

with box being a label.

foreach (string i in Session.Contents) {
  if (Session[i] != null) {
    box.Text += i + " = " + Session[i].ToString() + "\n";
  }
}

Upvotes: 6

AaronS
AaronS

Reputation: 7713

Your easiest route is to just enable tracing. This will show you all of this information automatically. You can do this at the page, or the application level.

Here is a quick tutorial on getting started.

Upvotes: 6

Andrew Hare
Andrew Hare

Reputation: 351616

Use HttpRequest.Params:

Gets a combined collection of QueryString, Form, ServerVariables, and Cookies items.

Upvotes: 4

Related Questions