I am trying to have a hit counter for my website but the following code will not write the text file to hold the counter. I am fairly new to this so I am shooting from the hip and any help would be greatly appreciated. This was originally a frontpage web (I don't know if this could possibly have an affect or not). I have full permissions to the 'counter' directory.
Code:
Sub Application_OnStart
Dim fsVisitors 'FileSystemObject object
Dim fileVisitors 'TextStream object
Set fsVisitors = Server.CreateObject ("Scripting.FileSystemObject")
Set fileVisitors = fsVisitors.OpenTextFile("C:\InetPub\[URL unfurl="true"]wwwroot\counter\IntraHome.txt")[/URL]
If err.number <> 0 Then
Set fileVisitors = fsVisitors.CreateTextFile("C:\InetPub\[URL unfurl="true"]wwwroot\counter\IntraHome.txt")[/URL]
err.clear
End If
'Read counter value from text file
Application("visitors") = fileVisitors.ReadLine
fileVisitors.Close
end sub
Sub Session_OnStart
Application.Lock
Application("visitors") = Application("visitors") + 1
Application.Unlock
end sub
Sub Application_OnEnd
Dim fsVisitors 'FileSystemObject object
Dim fileVisitors 'TextStream object
Set fsVisitors = Server.CreateObject("Scripting.FileSystemObject")
Set fileVisitors = fsVisitors.CreateTextFile("C:\InetPub\[URL unfurl="true"]wwwroot\counter\IntraHome.txt",[/URL] True)
'Write counter value to text file
fileVisitors.Writeline(Application("visitors"))
fileVisitors.Close
End Sub