How to view Session Variables in Visual Studio 2008 Debugger?

28,476

Solution 1

It's pretty simple to inspect the session during debug. Just put a breakpoint in your code and just highlight your Session code (eg. highlight: Session["first_name"]) then right click and select QuickWatch....

This will setup up a watch on your Session for the value you had defined. You can also inspect other Session elements by adjusting the Expression field in the QuickWatch window and clicking the Reevaluate button.

Solution 2

In VS you can just put 'Session["first_name"]' in the Immediate Window and execute while the code is running. That will return the value that it holds.

If you can't find it go to: View > Other Windows > Command Window, or press Ctrl+W, A

It will look like this: Screenshot:

I know its a bit of a late reply but for anyone else who is interested, I hope this helps!

Solution 3

Isn't it HttpContext.Current.Session("..."), I ask as I haven't used ASP.NET for a long time.

Share:
28,476
Dave Mackey
Author by

Dave Mackey

Love to code: Python, JS, C#, PHP, SQL, VB.NET, HTML, CSS. In ancient days I coded in QuickBasic, ASP, and VBScript. I'm a friendly introvert with solid communication skills. I work hard and have refined problem solving skills. When I was younger I worked in a variety of industries (commercial fisherman, stone mason, lawn care, factory, custodial, youth leader). I settled on IT and have experience working in a startup, higher education, and with non-profits.

Updated on July 09, 2022

Comments

  • Dave Mackey
    Dave Mackey almost 2 years

    Usually using Visual Studio's debugger is a breeze. Scanning through Locals quickly shows the values of variables, etc. However, I'm at a loss how to find out the values contained in session state variables? Can anyone give me a hand? Let's say I put a breakpoint right after:

    Session["first_name"] = "Rob Roy";
    

    How do I view the value contained in Session["first_name"] from locals?

  • Dave Mackey
    Dave Mackey about 14 years
    Hmmm...Wasn't able to find anything like that.
  • Rohit Sharma
    Rohit Sharma about 14 years
    @davemackey If this helped you and is correct, please mark it as the correct answer :)
  • Dalbir Singh
    Dalbir Singh almost 14 years
    Thank you soo much, I've been going through those stupid tree menus and getting nowhere!!
  • Steve Chambers
    Steve Chambers about 11 years
    I'm looking for a way to view all the Session values at once. I can see all the keys but not their associated values. Do you know if this is possible or can it only be done one-by-one as per your answer?
  • Rohit Sharma
    Rohit Sharma about 11 years
    @SteveChambers one by one only. If you have all the keys, there is no reason why you couldn't iterate through them and display the values.
  • Steve Chambers
    Steve Chambers about 11 years
    @Kelsey thanks - a shame it isn't possible to view all key/values at once, especially as the Immediate Window doesn't allow looping. The one-by-one approach is doable but not ideal.
  • Chris Catignani
    Chris Catignani over 6 years
    You would use HttpContext.Current.Session("...") outside a Web Form...like in another class.. or DLL.