Thursday 3 February 2011

How to inspect Session contents in Visual Studio

Wouldn't it be nice if you didn't have dig deep into the Session object when all you want to do is inspect it's contents?

Well, until that becomes an available option in Visual Studio, keep this little code snippet close by, insert above a breakpoint at which you want to inspect the state of the Session and then put a Watch (right click, Add Watch) on the Dictionary sessionValues:


Dictionary<string, object> sessionValues = new Dictionary<string, object>();
foreach (var key in HttpContext.Current.Session.Keys)
sessionValues.Add(key.ToString(), HttpContext.Current.Session[key.ToString()]);

No comments:

Post a Comment