Session Dump Utility
I'm currently working on a project where we are storing quite a bit of data in Session for the user. Naturally, QA had a hard time testing whether or not something actually was stored in Session. So, we wrote a little page that showed the values of what we put in Session. The problem with this approach is that every time we added another item to Session, or removed an item, we would have to fix this page to include the new and remove the old. It got to be very tiresome.
I had just finished doing some work with reflection (my first time ever). And it occurred to me that I could use reflection to show everything that was stored in Session in such a way that it could be written once and never need to be updated.
Here's the basic rundown of what the utility does (see attached .zip file):
- On the page load, iterate over all items in Session
- Print the Key of the item
- If the value of the item is a native data type (int, bool, decimal -- including String and DateTime objects) print the value
- If the value is an object...
- Iterate over all the public properties of the object
- Print the Property Name
- If the value of the Property is a native data type, print it
- If it is an object, GOTO #5
In the end, I always get to a native data type (or String or DateTime), so we wouldn't end up in an endless loop. Here's a sample of what it displays:
As an added bonus, it will also display the approximate size of all the objects (in bytes/kilobytes).
This utility has been very helpful for me, to make sure I know what is in Session, without having to step through the code in debug mode and stop and interrogate the Session object to find the specific value (or values) I'm looking for. This has also been very helpful to QA so that they can see what is put into Session.