Solved

re-writing the Session Object

Posted on 2004-09-13
12
265 Views
Last Modified: 2008-02-01
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  :-)
0
Comment
Question by:cwolves
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 19

Expert Comment

by:peh803
ID: 12048724
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
 
LVL 9

Author Comment

by:cwolves
ID: 12048750
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
 
LVL 19

Expert Comment

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

(just curious)
peh803
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:cwolves
ID: 12048883
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
 
LVL 19

Expert Comment

by:peh803
ID: 12048952
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
 
LVL 9

Author Comment

by:cwolves
ID: 12048999
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
 
LVL 28

Accepted Solution

by:
sybe earned 500 total points
ID: 12052153
=====================================================
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
 
LVL 9

Author Comment

by:cwolves
ID: 12052762
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
 
LVL 9

Author Comment

by:cwolves
ID: 12052776
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
 
LVL 19

Expert Comment

by:peh803
ID: 12054136
cwolves -- very nice.  I like it a lot...particularly the bit about serializing / deserializing the arrays...

good work,
peh803
0
 
LVL 9

Author Comment

by:cwolves
ID: 12054300
I'll post the results here within the next day or two (whenever I have time to really work on it)
0
 
LVL 19

Expert Comment

by:peh803
ID: 12054369
cool...I'll keep my eyes opened for it.

peh803
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Query still returning duplicates 5 51
Index on a Table 6 31
ASP exit 10 28
Getting robots.txt Error 9 24
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question