Weird PropertyBag problem, values won't change



I'm in the process of writing a couple server programs that use
sessions to control what goes on with users. Instead of using classes
or structures to store this information, I'm using PropertyBags for two
reasons: 1) I can store the data in a file if need be, and 2) I can
dynamically add values as needed. Since all the values being stored are
scalars (no objects of any kind, all booleans, strings, integers,
etc.), I figured this would make life much easier. One of the values
used is a Timeout value to kick users off that have been idle for too
long. I have two classes:

CSession - Data storage class for a session. This is basically a
wrapper for the PropertyBag object.

CSessions - Collection of CSession objects for all logged in users.

Here's my code for CSession:

---------------------------------------------------------------
Option Explicit

Private m_Data As New PropertyBag
Private m_ID As String

Public Property Let ID(ByVal vData As String)
m_ID = vData
End Property

Public Property Get ID() As String
ID = m_ID
End Property

Public Property Get Item(ByVal Key As String) As String
On Error Resume Next
Item = m_Data.ReadProperty(Key)
On Error GoTo 0
End Property

Public Property Let Item(ByVal Key As String, ByVal Data As String)
m_Data.WriteProperty Key, Data
End Property
---------------------------------------------------------------

Fairly simple, right?

And the code for CSessions:

---------------------------------------------------------------
Option Explicit

'local variable to hold collection
Private mCol As Collection

Public Function Add(ID As String) As CSession
'create a new object
Dim objNewMember As CSession
Set objNewMember = New CSession


'set the properties passed into the method
objNewMember.ID = ID
mCol.Add objNewMember, ID

'return the object created
Set Add = objNewMember
Set objNewMember = Nothing


End Function

'// Item -- returns a given CSession object. This code was originally
'// generated from the VB Class Builder wizard. However, in an effort
to be
'// more flexible, I have modified it to add a new CSession object if
the
'// requested one doesn't exist. Thus, it is now perfectly legal to
say:
'//
'// CSessions("ThisItem") = "Hello, world!"
'//
'// (if "Hello, World" was a session and not a string) even though
'// "ThisItem" doesn't exist in the collection.
'//
Public Property Get Item(ID As String) As CSession
If Exists(ID) Then
Set Item = mCol(ID)
Else
Set Item = Add(ID)
End If
End Property

Public Property Get Count() As Long
Count = mCol.Count
End Property


Public Sub Remove(ID As String)
mCol.Remove ID
End Sub

'// Exists -- Dirty little hack to see if a specified CSession object
'// exists within the collection.
'//
Public Function Exists(ID As String) As Boolean
On Error Resume Next
Exists = (Not (mCol(ID) Is Nothing))
End Function

Public Property Get NewEnum() As IUnknown
'this property allows you to enumerate
'this collection with the For...Each syntax
Set NewEnum = mCol.[_NewEnum]
End Property


Private Sub Class_Initialize()
'creates the collection when this class is created
Set mCol = New Collection
End Sub


Private Sub Class_Terminate()
'destroys collection when this class is terminated
Set mCol = Nothing
End Sub
---------------------------------------------------------------

When a user logs in, I call the Add method on a CSessions object with a
automatically generated session ID. They are then immediately given a
Timeout of "now + 30 seconds" or whatever the program calls for. In
other words:

Private Sessions As New CSessions
Sub Login(User)
Dim oSess As CSession
Set oSess = Sessions.Add(NewSessionID)
oSess("Timeout") = DateAdd("s", 30, Now)
'Other session data follows
End Sub

Now, that's all well and good. No problem. I can access the Timeout
value later on via Sessions(SessionID)("Timeout") or any other value
that I store on login.

However, when I go to change any of the values, they don't stay
written. Here's what I mean:

Debug.Print "Current timeout: " & Sessions(SessionID)("Timeout")
UpdateTimeout SessionID
Debug.Print "New timeout: " & Sessions(SessionID)("Timeout")
Sub UpdateTimeout(ByVal SessionID As String)
Debug.Print "Updating timeout on session " & SessionID
Sessions(SessionID)("Timeout") = DateAdd("s", 30, Now)
Debug.Print "Timeout has been changed to " &
Sessions(SessionID)("Timeout")
End Sub

Upon being run, the debug window goes something like this:

Current timeout: 1/17/2006 2:18:43 AM
Updating timeout on session HF2
Timeout has been changed to 1/17/2006 2:19:13 AM
New timeout: 1/17/2006 2:18:43 AM

The timeout is ONLY UPDATED inside the sub procedure. As soon as it
exits, it's reverted back to the way it was before.

Does ANYONE have ANY IDEA what is going on with my code?

.



Relevant Pages

  • Re: Global.asax Session_OnEnd not firing
    ... the session timeout has been reached due to no requests from the client. ... > Private Sub Page_Init(ByVal sender As System.Object, ... > Public Shared Function GetSessionCount(ByVal AppPath As String, ...
    (microsoft.public.dotnet.general)
  • Re: Global.asax Session_OnEnd not firing
    ... > the session timeout has been reached due to no requests from the client. ... >> End Sub ... >> Public Shared Function GetSessionCount(ByVal AppPath As String, ...
    (microsoft.public.dotnet.general)
  • Re: Displaying the all the name-value pairs of the session object?
    ... Sub Page_Load ... Dim Item as String ... Juan T. Llibre ... > I want to display all the name-value pairs of the session object....how can ...
    (microsoft.public.dotnet.framework.aspnet)
  • Global.asax Session_OnEnd not firing
    ... I am trying to limit the amount of connections a browser session can have. ... Public Class WebForm1 ... End Sub ... SessionID As String) As Integer ...
    (microsoft.public.dotnet.general)
  • server-side JavaScript: Prototypes of built-in classes, objects and functins
    ... Session object (disk-based session variables for data persistence ... File class (manipulation of files on server, ie. open, close, read, ... //Methods Cgi.queryCgi.postCgi.anyby default return an empty string if requested var not found ...
    (comp.lang.javascript)