Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2004, 03:33 PM
Registered User
 
Join Date: Jan 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default global.asa not firing

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.
 
Old February 15th, 2004, 03:53 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old February 15th, 2004, 04:03 PM
Registered User
 
Join Date: Jan 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old February 15th, 2004, 04:33 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old February 16th, 2004, 08:18 AM
Registered User
 
Join Date: Jan 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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("blahbla h.txt"), 2)
 Else
  Set objFileTS = objLogFileFSO.CreateTextFile(server.mappath("blahb lah.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?
 
Old February 16th, 2004, 08:33 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old February 16th, 2004, 08:38 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

One more thing:
Code:
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.
 
Old February 16th, 2004, 08:42 AM
Registered User
 
Join Date: Jan 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Global.asa pushpa Classic ASP Basics 19 March 9th, 2007 08:30 AM
About Global.asa pbcatan Classic ASP Databases 2 December 4th, 2006 12:40 AM
Global.asa gmoney060 Classic ASP Basics 3 September 25th, 2004 09:11 AM
Global.asa madsmad ASP.NET 1.0 and 1.1 Basics 1 August 17th, 2003 07:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.