re-writing the Session Object

Okay, I'm re-writing the ASP Session object so that it's pulled from a database and thus can be used in a server-farm environment.

questions:

1) How do I get a 'default' function to apply to a class?  ie to reference session objects you can use session("variable").  I want to be able to do this with a defined class, ie classname("variable") and not classname.somefunction("variable")
2) if the first is possible, how do I determine if the call is for a read or a write?  ie [var x = session("blah")] vs [session("blah") = 5]
3) I'm almost certain that 1 & 2 aren't possible in ASP.  This being the case, how do I do this in VB?

4) How do browsers determine what a "session cookie" is?  if you go to IE's privacy settings you can over-write the default cookie settings and there's a checkbox that says "always allow session cookies".  Is this determined on the cookie name (ie ASPSESSIONIDQSBTSATA), the expiration (in which case what would I need to set the expiration to to make it work), or is it something that I don't have control over in raw ASP?

thanks  :-)
LVL 9
cwolvesAsked:
Who is Participating?
 
sybeConnect With a Mentor Commented:
=====================================================
1) How do I get a 'default' function to apply to a class?  ie to reference session objects you can use session("variable").  I want to be able to do this with a defined class, ie classname("variable") and not classname.somefunction("variable")
=====================================================

You can only have a single default function or property.
If you use a property, then this sample code might help you:

<%

Class Test
    Private sDefault

    Private Sub Class_Initialize
        sDefault = "default value"
    End Sub


    Public Default Property Get Value
       Value = sDefault
    End Property

    Public Property Let Value(ByVal s)
       sDefault = s
    End Property
End Class


Dim oTest, sDefault
Set oTest = new Test
sDefault = oTest
Response.write sDefault
%>

======================================================
2) if the first is possible, how do I determine if the call is for a read or a write?  ie [var x = session("blah")] vs [session("blah") = 5]
======================================================

Use of property: Get = read, Let = write

===================================
proposal for solving your problem
===================================

All in all, you might want to use a Dictionary object. In fact that is very close to a Session-Object. Many common methods and properties. No need to rewrite anything

<%
Dim oDictionary
Set oDictionary = Server.CreateObject("Scripting.Dictionary")
For Each element in Session.Contents
    If IsObject(Session.Contents(element)) Then
        Set oDictionary(element) = Session.Contents(element)
    Else
        oDictionary(element) = Session.Contents(element)
    End If
Next

%>
0
 
peh803Commented:
I assume ASP.NET isn't an option?  

I'm sure you know that you're reinventing the wheel here...  ASP.NET has this specific built-in functionality (serializing the session object to a database for use in server-farm environments).

That said, I did this a year or so ago (rewrote the session object in classic asp using a database backend), but I didn't get as fancy as it sounds you're getting.  It sounds like yours is going to be very cool :)  ...

Good luck,
peh803
0
 
cwolvesAuthor Commented:
nope, .net isn't an option  :-)

well I've already re-written the object and can call it using dSession.getData("varname"), etc....

I want to be able to use Session("blah") and not dSession("blah").  I just figured out how to do this (how to overwrite the session object).

The only other real issue is "default" functions...and how to use a session cookie if I'm not using the "real" session object  ;-)
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
peh803Commented:
Like I said, sounds sweet.  You doing this with a component or with straight, non-compiled asp?  SQL Server 2000?

(just curious)
peh803
0
 
cwolvesAuthor Commented:
trying to do it in non-compiled ASP...don't think I can have a "default" function in a class though.  I'll post the code when done if you're interested

and yeah, MSSQL2000
0
 
peh803Commented:
yeah, I'd be interested if you don't mind.  Although I gotta tell ya, I'm being of no help to you regarding this question :).  Just drooling over the cool-ness of what you're doing.  Also, I think you're right about setting default functions in non-compiled ASP Classes...I don't think you can do it (although I've never tried).

You using any stored procedures on the db side to do anything?

How do you manage the session among users?  Pass a guid around?

peh803
0
 
cwolvesAuthor Commented:
ALTER  PROCEDURE dbo.sp_loadsession
      @s_id      char(32),
      @IP      char(32)
AS

      DELETE FROM session_data WHERE s_id IN (SELECT s_key FROM sessions WHERE DateDiff(s, active, GetDate()) >= timeout * 60)
      DELETE FROM sessions WHERE DateDiff(s, active, GetDate()) >= timeout*60

      DECLARE @s_key char(32)
      SELECT @s_key=(SELECT s_key FROM sessions WHERE s_key=@s_id)

      if @s_key<>'' AND @s_key IS NOT NULL
      BEGIN
            UPDATE sessions SET IP=@IP, active=getdate()
      END ELSE BEGIN
            INSERT INTO sessions(s_key, IP) VALUES(@s_id, @IP)
      END

      SELECT * FROM session_data WHERE s_id=@s_key


ALTER  PROCEDURE dbo.sp_remove_session_vars
      @s_id      char(32),
      @IP      char(4),
      @var      varchar(255)
AS
      if @var='*'
      begin
            DELETE FROM session_data WHERE s_id=@s_id
      end else begin
            DELETE FROM session_data WHERE s_id=@s_id AND varname=@var
      end



ALTER  PROCEDURE dbo.sp_terminate_session
      @s_id      char(32),
      @IP      char(4)
AS
      DELETE FROM session_data WHERE s_id=@s_id
      DELETE FROM sessions WHERE s_key=@s_id




I'm storing everything -as it's original data type- except for object which I can't store (and which shouldn't be stored in a session object anyway).

ie session("tmpdata") = array(1, 2, 3, 4, 5)
tmp = session("tmpdata") ' this will still be an array
0
 
cwolvesAuthor Commented:
yeah, there's a dictionary object in the class.  The class is done (except for the above mentioned changes).

and wow to the 'default' keyword...didn't know about that  :-)  why can't I add an argument to the get property though?
0
 
cwolvesAuthor Commented:
nevermind, figured it out...I needed another argument on the let.  apparently it passes two arguments if you do:

obj("whatever") = 5

the arguments being "whatever", 5.  That's cool  :-)
0
 
peh803Commented:
cwolves -- very nice.  I like it a lot...particularly the bit about serializing / deserializing the arrays...

good work,
peh803
0
 
cwolvesAuthor Commented:
I'll post the results here within the next day or two (whenever I have time to really work on it)
0
 
peh803Commented:
cool...I'll keep my eyes opened for it.

peh803
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.