|
Subject:
|
global.asa not firing
|
|
Posted By:
|
pill
|
Post Date:
|
2/15/2004 2:33:00 PM
|
I'm using this code to trigger a file being written by the session on end function for testing - I'm going to use this to edit a database when it goes live.
I'm using this code:
If objLogFileFSO.FileExists("blahblah.txt") Then Set objFileTS = objLogFileFSO.OpenTextFile(blahblah.txt, 2) Else Set objFileTS = objLogFileFSO.CreateTextFile(blahblah.txt, True) End If
the session timeout is set to 10 seconds so as far as I know it should be working fine.
Anyone know of any reason why this might not be working?
pete.
|
|
Reply By:
|
Imar
|
Reply Date:
|
2/15/2004 2:53:32 PM
|
Is this real code or just an example for this post?
Your filenames are not enclosed in quotes, causing an error. Since the Session_OnEnd does not have a fire.
Session timeout is usually in minutes. How did you set it to seconds?
Cheers,
Imar
--------------------------------------- Imar Spaanjaars Everyone is unique, except for me.
|
|
Reply By:
|
pill
|
Reply Date:
|
2/15/2004 3:03:19 PM
|
OOps - not my code.
I've tried it with the speach marks round it (oops, missed that one) but it still isn't creating the file.
I set the timeout using the connection timeout is set to 10seconds through iis - is this where you set the server timout????
any thoughts.
Pete
|
|
Reply By:
|
Imar
|
Reply Date:
|
2/15/2004 3:33:50 PM
|
The Session Timeout in IIS is set on the Application Configuration dialog for your application (or Virtual Directory).
To change it, right click your app (or Virtual Directory) in IIS and choose Properties. On the Web site (or Directory) tab, click the Configuration button and then open the Options tab. Timeout is in minutes, so you can't set it to a value in seconds.
For an article about writing to text files from Session_OnEnd, take a look here: http://Imar.Spaanjaars.Com/QuickDocID.aspx?QUICKDOC=164 It explains how to create a hit counter with a text file.
Cheers,
Imar
--------------------------------------- Imar Spaanjaars Everyone is unique, except for me.
|
|
Reply By:
|
pill
|
Reply Date:
|
2/16/2004 7:18:49 AM
|
Thanks for the response, Imar -
I've now configured the session time out correctly to one minute (I was altering the script time out).
Still, though, the code isn't working. Here's my current global asa file:
<Script Language="VBScript" RUNAT="Server"> Sub Application_OnStart Application( "WhosOnline" ) = 4 End Sub Sub Application_OnEnd End Sub Sub Session_OnStart session. Application.Lock Application( "WhosOnline" ) = Application( "WhosOnline" )+1 Application.UnLock End Sub
Sub Session_OnEnd Application.Lock Application( "WhosOnline" ) = Application( "WhosOnline" )-1 Application.UnLock if Session("MM_Username")<>"" then Set objLogFileFSO = CreateObject("Scripting.FileSystemObject") If objLogFileFSO.FileExists("blahblah.txt") Then Set objFileTS = objLogFileFSO.OpenTextFile(server.mappath("blahblah.txt"), 2) Else Set objFileTS = objLogFileFSO.CreateTextFile(server.mappath("blahblah.txt"), True) End If end if strText = "session on end script working" objFileTS.WriteLine strText End Sub </Script>
in the session onend, the first three lines are a counter - this works fine, so I know the function is firing. Can you see any reason why this isn't working?
|
|
Reply By:
|
Imar
|
Reply Date:
|
2/16/2004 7:33:11 AM
|
If I were you, I'd cut the code to a normal page and try to make it work. When it works as it should, move it to the global.asa file.
Thinks to consider:
1. Make sure you use Server.MapPath as well for the FileExists check. Right now, the code checks whether a file somewhere in your system directory exists. It doesn't, so it tries to create it. However, it probably already exists in your Web folder, so you get an error.
2. You Set your objects within the If Session("MM_Username") block, yet after the last End If, you try to use WriteLine method of the objFileTS object (which doesn't exists when MM_Username equals "".
Cheers,
Imar
--------------------------------------- Imar Spaanjaars Everyone is unique, except for me.
|
|
Reply By:
|
Imar
|
Reply Date:
|
2/16/2004 7:38:14 AM
|
One more thing:Sub Session_OnStart
session.
Application.Lock I think your Session_OnStart will also fail, because of the session.
Cheers,
Imar
--------------------------------------- Imar Spaanjaars Everyone is unique, except for me.
|
|
Reply By:
|
pill
|
Reply Date:
|
2/16/2004 7:42:27 AM
|
Oops - aye, true, the session. isn't actually in it, I was playing with the file before the cut n paste. :)
I'll try the cut n paste like you suggest - good idea.
Thanks.
|