Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view Session Variables in Visual Studio 2008 Debugger?

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?

like image 601
Dave Mackey Avatar asked Mar 30 '10 23:03

Dave Mackey


People also ask

How do I show variables in Visual Studio debugger?

When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable. If the variable is an object, you can expand the object by clicking on the arrow to see the elements of that object.

How do I see variable values in Visual Studio?

Add a variable to a Watch windowRight-click the variable in the data tip, and select Add Watch. The variable appears in the Watch window. If your Visual Studio edition supports more than one Watch window, the variable appears in Watch 1.

How do I view local variables in Visual Studio?

To open the Locals window, while debugging, select Debug > Windows > Locals, or press Alt+4. This topic applies to Visual Studio on Windows.


3 Answers

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.

like image 154
Kelsey Avatar answered Sep 29 '22 12:09

Kelsey


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!

like image 30
P-Bagels Avatar answered Sep 29 '22 10:09

P-Bagels


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

like image 42
Preet Sangha Avatar answered Sep 29 '22 12:09

Preet Sangha