[Download Code]
When developing web sites there are many times that session state has to be saved between pages. Maybe you are writing an Intranet app that takes 20 pages to do one action. Or, maybe you have an Internet site that state must be saved as the user randomly navigates through the site. Whatever the reasons, you need to save session state and are concerned about over-filling the memory. Regardless of what method of storing session state you choose the point of this article is to make it easier for the developer and to keep the number of actual session variables down to one.
Having worked on many ASP.NET projects it seems we were always faced with code bloat just from passing data in and out of a page. On one particular project I was tasked with exploring different ways to store data, reduce the memory footprint, and ease the developer's burden. The first method we came up with was a class structure that contained a property for each variable we needed in our app.
Storing a full blown object in memory was not saving us much in the way of memory footprint. After looking at all of our data we discovered that all of the data we needed to store was numbers, strings and dates. That's when we made the move to exploring XML as a possible storage medium. One of the biggest benefits of XML is that it is a string. Another is that it is easy to deal with. So now that we have decided on an XML approach it is time to dive into the easiest method of developing this type of solution.