Solved

re-writing the Session Object

Posted on 2004-09-13
12
261 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
syntax error on ASP ? 6 46
VBScript FormatCurrency - how to change the currency symbol 4 46
Classic ASP, Search Recordset on pick list change 1 65
is this a cms? 8 60
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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