Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view all Session key/value pairs when debugging in Visual Studio?

When debugging in Visual Studio (.Net MVC4), is it possible to see all Controller.Session key/values at once? I can view all keys by typing Session into QuickWatch and expanding "Results View". E.g:

    Results View
    [0] "IsPlaced"  
    [1] "FromSLC"   
    [2] "PersonalId"    
    [3] "FullName"  

Am aware that individual values can be inspected like this but haven't been able to get a list of all keys and values at the same time. Surely this must be possible, either in QuickWatch or the Immediate Window?

like image 535
Steve Chambers Avatar asked Nov 03 '22 00:11

Steve Chambers


2 Answers

I don't see an easy way to do that, your best bet would be to write a method that takes in an HttpSessionState and converts it to a dictionary, and then calling that method from the QuickWatch window. A somewhat more complex solution would be to write your own DebuggerTypeProxy for HttpSessionState and put it in your autoexp.cs file, the advantage of this approach being that it will work across different applications and won't force you dirty up your solution with code that's only of use for debugging.

like image 143
Omer Raviv Avatar answered Nov 12 '22 15:11

Omer Raviv


Idea A You could create a extension Method on the Session Object which prints its content the way you need it. Then call this Method in the immediate Window or add a watch to it.

Idea B You could also create a custom visualizer which displays your Session Object like you intend. There is a basis guide here: http://msdn.microsoft.com/en-us/library/ms164759.aspx

This also means adding code to your project but just like extension methods it will stay at a very defined place.

like image 43
Th 00 mÄ s Avatar answered Nov 12 '22 14:11

Th 00 mÄ s