birstein
asked on
Using BrowserHawk Objects in Global.asa Efficiently
I've got a GLOBAL.ASA file that is presently counting Active Users (see below). However, now I have Browser Hawk installed on my dedicated server and I would like to add code to GLOBAL.ASA that records in an Access database for each user session whether the user has FLASH installed or not. The code to do this is basically this:
Dim objConn
Dim ConnectionString
Set objConn = Server.CreateObject("ADODB .Connectio n")
ConnectionString = "Provider=Microsoft.Jet.OL EDB.4.0; Data Source=path to database;"
objConn.Open ConnectionStringset bhObj = Server.CreateObject("cySca pe.browser Obj")
bhObj.SetExtProperties "plugin_flash"
bhObj.GetExtPropertiesEx
flash = bhObj.Plugin_Flash
if flash = 0 Then
objConn.Execute(" INSERT INTO browserstats ( flash ) SELECT -0 AS flashinst")
else
objConn.Execute("INSERT INTO browserstats ( flash ) SELECT -1 AS flashinst")
end if
objConn.Close
Set objConn = Nothing
What I'm unsure about is how to put this code into my present GLOBAL.ASA efficiently so that I only open the BrowserHawk object once, etc. Here is my present GLOBAL.ASA:
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Application_OnStart
' Set our user count to 0 when we start the server
Application("ActiveUsers") = 0
End Sub
Sub Session_OnStart
' Change Session Timeout to 20 minutes (if you need to)
Session.Timeout = 20
' Set a Session Start Time
' This is only important to assure we start a session
Session("Start") = Now
' Increase the active visitors count when we start the session
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.UnLock
End Sub
Sub Session_OnEnd
' Decrease the active visitors count when the session ends.
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.UnLock
End Sub
</SCRIPT>
Any suggestions very much appreciated!
Kathryn
Dim objConn
Dim ConnectionString
Set objConn = Server.CreateObject("ADODB
ConnectionString = "Provider=Microsoft.Jet.OL
objConn.Open ConnectionStringset bhObj = Server.CreateObject("cySca
bhObj.SetExtProperties "plugin_flash"
bhObj.GetExtPropertiesEx
flash = bhObj.Plugin_Flash
if flash = 0 Then
objConn.Execute(" INSERT INTO browserstats ( flash ) SELECT -0 AS flashinst")
else
objConn.Execute("INSERT INTO browserstats ( flash ) SELECT -1 AS flashinst")
end if
objConn.Close
Set objConn = Nothing
What I'm unsure about is how to put this code into my present GLOBAL.ASA efficiently so that I only open the BrowserHawk object once, etc. Here is my present GLOBAL.ASA:
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Application_OnStart
' Set our user count to 0 when we start the server
Application("ActiveUsers")
End Sub
Sub Session_OnStart
' Change Session Timeout to 20 minutes (if you need to)
Session.Timeout = 20
' Set a Session Start Time
' This is only important to assure we start a session
Session("Start") = Now
' Increase the active visitors count when we start the session
Application.Lock
Application("ActiveUsers")
Application.UnLock
End Sub
Sub Session_OnEnd
' Decrease the active visitors count when the session ends.
Application.Lock
Application("ActiveUsers")
Application.UnLock
End Sub
</SCRIPT>
Any suggestions very much appreciated!
Kathryn
Would this not work if you included your database update inside the subroutine Session_OnStart ?
ASKER
Yes, I think it would, but do I want to create the connection and close the connection everytime a new session starts? Or is it much more efficient to just open the connection (objConn.Open ConnectionString) just once and keep it open.
I'm also thinking the same would be true for opening the BrowserHawk object:
set bhObj = Server.CreateObject("cySca pe.browser Obj")
What do you think?
I'm also thinking the same would be true for opening the BrowserHawk object:
set bhObj = Server.CreateObject("cySca
What do you think?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dear alorentz:
I'll put everything in the Session_OnStart sub as you suggest. This is just what I wanted to know - what makes the most overhead. . .
Kathryn
I'll put everything in the Session_OnStart sub as you suggest. This is just what I wanted to know - what makes the most overhead. . .
Kathryn
Best bet is to open and close all objects when you need them...keeping them open is not efficient.
Good Luck!
Good Luck!