Session Variables - Saving with XML
page 1 of 4
Published: 22 Dec 2004
Unedited - Community Contributed
Abstract
When developing web sites there are many times that session state has to be saved between pages. Here is a way to store all of your session variables in a single string and give access to all variables across all pages.
by Keith Barrows
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 22237/ 30

Introduction

[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.


View Entire Article

User Comments

Title: zzc   
Name: zcc
Date: 2012-08-01 6:53:38 AM
Comment:
zc
Title: Problem   
Name: Mohammad
Date: 2005-10-07 2:24:29 AM
Comment:
sample cant run
Title: Are you nuts?   
Name: Curious
Date: 2004-12-22 9:50:48 PM
Comment:
"Whatever the reasons, you need to save session state and are concerned about over-filling the memory."

So, you add on all the extra xml tags and the xmldocument with its collections of nodes to work with and that is somehow less memory intensive?

"Storing a full blown object in memory was not saving us much in the way of memory footprint."

Everything in .NET is an object/class. Strings included.

If you really needed to convert your session values to xml. You would create a class with properties that get/set your session variables in the get/set statements and convert the session values to the proper .NET datatype.

Then, use the System.Xml.Serialization.XmlSerializer to quickly and easily convert the class properties to an xml string.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-28 10:16:51 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search