22

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?

zappee
  • 20,148
  • 14
  • 73
  • 129
Dave Mackey
  • 4,306
  • 21
  • 78
  • 136

3 Answers3

27

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.

Kelsey
  • 47,246
  • 16
  • 124
  • 162
  • @davemackey If this helped you and is correct, please mark it as the correct answer :) – Kelsey Apr 01 '10 at 19:21
  • 2
    Thank you soo much, I've been going through those stupid tree menus and getting nowhere!! – Dalbir Singh Aug 11 '10 at 10:33
  • 1
    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? – Steve Chambers Apr 16 '13 at 08:42
  • @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. – Kelsey Apr 16 '13 at 14:15
  • 1
    @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. – Steve Chambers Apr 16 '13 at 15:05
12

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!

P-Bagels
  • 147
  • 1
  • 2
  • 13
1

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

Preet Sangha
  • 64,563
  • 18
  • 145
  • 216