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