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

When debugging in Visual Studio (.Net MVC4), is it possible to immediately see all the Controller.Session key / values? I can view all the keys by entering Session in QuickWatch and expanding the "Results Overview". For instance:

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

We know that individual values ​​can be checked like this , but could not get a list of all the keys and values at the same time. Of course, should this be possible either in QuickWatch or in the Immediate window?

+4
source share
3 answers

I don’t see an easy way to do this, it’s best to write a method that takes an HttpSessionState and converts it to a dictionary, and then calls this method from the QuickWatch window. A slightly more complicated solution would be to write your own DebuggerTypeProxy for the HttpSessionState and put this in your autoexp.cs file , the advantage of this approach is that it will work in different applications and will not force you to pollute your solution with code that is used only for debugging.

+2
source

Idea A You can create an extension method for a session object that prints its contents as you need. Then call this method in the immediate window or add a clock to it.

Idea B You can also create your own visualizer that displays your session object as you plan. There is a basics guide here: http://msdn.microsoft.com/en-us/library/ms164759.aspx

It also means adding code to your project, but just like extension methods, it will remain in a very specific place.

+2
source

Try adding a namespace:

 using System.Diagnostics; 

On the page where your session was created, add the following:

 Debug.Write(Session["your session value or text"]); 
-1
source

All Articles