Session Variables - Saving with XML
page 3 of 4
by Keith Barrows
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 22151/ 47

Class - PageInfo & AppInfo

[Download Code]

It's time to take the Base Class we just created, inherit it, and extend it.  There are 2 classes in the attached project that use the BaseSessionClass.  The first class handles User based information and the second class handles Page based information.  This is where it gets fun.  No one can tell you what the right variables are for your application.  The first app I did this for, the decision was made to split the User from everything else.  It may be that having 1 object will work for you.  You could also have a half dozen objects.

When creating a class there are only a few things to keep in mind; that have to be created:

  • Default XML_BODY and SESSION_NAME
    const string XML_BODY = "<?xml version='1.0'?>
    <PageInfo myID='-1' EntryGroupID='-1' EntryGroup='-1' 
    ErrorPage='~\\defaultError.aspx' ErrorMessage='' ErrorReturnPage='' 
    historyDate='' currentChoice='0' ErrorNoItems='' ItemTotalCnt='0' 
    ReturnPage='' OtherXmlData='' />";
    const string SESSION_NAME = "PageInfoData";
  • Call to Base Class Constructor
    internal PageInfo(HttpContext appContext):base(appContext, SESSION_NAME, XML_BODY)
    {
    }
  • Expose the values through public properties

Since the decision was made to split the User from the rest of the variables one more class was added to wrap this into a whole.  We ended up calling this class App, pretty creative of us.  It makes it real simple to deal with all of your session information this way.

App.Page.ID = textControl.Text;
App.User.FirstName = textFName.Text;
App.User.LastName = textLName.Text;

 


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-04-24 5:08:18 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search