Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to browse all session variables in debug mode?

I am using Microsoft Visual Studio 2010 Professional and developing an asp.net / C# app. While in debug mode I can see the local variables under the "Locals" tab, and there is also something called "this" which expands into multiple tree structures. However, I am unable to find my Session variables name / value pair anywhere.

A friend suggested I use the "Immediate Window" tab and type the name of my Session variable (ie.,Session["SomeValue"] and press enter. This does give me the value of the Session variable. This is simple enough for a single session variable but when dealing with multiple variables it becomes a bit cumbersome.

Is there anyway that I can just browse to a section that stores the key / value pair for all my session variables, like I can for the local variables?

like image 214
Baxter Avatar asked Aug 15 '12 13:08

Baxter


2 Answers

There might be a more elegant way, but if I recall you can dump out Session name/value pairs when tracing is enabled.

  • enable tracing
  • execute a page
  • trace info is either appended to the bottom, or available at ~/Trace.axd

In web.config

<configuration>
  <system.web>
    <trace enabled="true" requestLimit="40" pageOutput="true|false" />
  </system.web>
</configuration>

http://msdn.microsoft.com/en-us/library/bb386420.aspx

Of course, this is only useful when there is a meaningful string representation of the object.

You could also look at writing a custom visualizer (I believe that's the correct term) that lets you inspect a type using your own custom functionality. I've seen this done for inspecting dynamic methods and it is quite useful, though I imagine it would be some effort to write one.

  • How to create a Visual-Studio string visualizer?
  • http://msdn.microsoft.com/en-us/library/e2zc529c.aspx
like image 57
Tim M. Avatar answered Sep 30 '22 02:09

Tim M.


Maybe you can try using Watch Windows. Type

httpContext.Session["your session variable name"]
like image 38
Jec Avatar answered Sep 30 '22 02:09

Jec