Solved

Using BrowserHawk Objects in Global.asa Efficiently

Posted on 2004-08-24
5
283 Views
Last Modified: 2012-05-05
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.Connection")
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=path to database;"

objConn.Open ConnectionStringset bhObj = Server.CreateObject("cyScape.browserObj")
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
0
Comment
Question by:birstein
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:darksinclair
ID: 11888522
Would this not work if you included your database update inside the subroutine Session_OnStart ?
0
 
LVL 1

Author Comment

by:birstein
ID: 11888540
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("cyScape.browserObj")

What do you think?
0
 
LVL 31

Accepted Solution

by:
alorentz earned 500 total points
ID: 11888560
Open and close in every session, that is the standard practice.  To much overhead onthe server to keep it open all the time.


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
   
 Dim objConn
Dim ConnectionString
Set objConn = Server.CreateObject("ADODB.Connection")
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=path to database;"

objConn.Open ConnectionStringset bhObj = Server.CreateObject("cyScape.browserObj")
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



End Sub
0
 
LVL 1

Author Comment

by:birstein
ID: 11888613
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
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11888690
Best bet is to open and close all objects when you need them...keeping them open is not efficient.

Good Luck!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calculating value of records from a column - classic asp 7 87
ASP Focus problem 3 68
Save ms data to server side. 19 55
Syntax for query to update table 2 29
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

828 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