Hi!
Im trying to use the Session EventHandlers in a web application, but it seems like the Session_End EventHandler does not want to work. I accually want to read from a text file as soon as the session ends and then change the values in the text file. Ive set Session.TimeOut to one minute just to see it work, but the code does not run. The Session_Start Event does work though! Maybe I dont understand the Session scope correctly.
Here is the code that Im using. Please help!
Emile
Im trying to use the Session EventHandlers in a web application, but it seems like the Session_End EventHandler does not want to work. I accually want to read from a text file as soon as the session ends and then change the values in the text file. Ive set Session.TimeOut to one minute just to see it work, but the code does not run. The Session_Start Event does work though! Maybe I dont understand the Session scope correctly.
Here is the code that Im using. Please help!
Code:
Sub Session_Start(Byval sender As Object, Byval e as EventArgs)
Dim myReader as StreamReader
myReader = File.OpenText(Server.MapPath("onlineUsers/onlineUsers.txt"))
Dim strCountValue as String
strCountValue = ""
while myReader.Peek() <> -1
strCountValue = strCountValue & myReader.ReadLine()
End while
myReader.Close()
Dim strInt as Integer
strInt = Convert.ToInt32(strCountValue) + 1
Dim myWriter as StreamWriter
myWriter = File.CreateText(Server.MapPath("onlineUsers/onlineUsers.txt"))
myWriter.Write(strInt)
myWriter.Close()
End Sub
Sub Session_End(Byval sender As Object, Byval e as EventArgs)
Dim myReader2 as StreamReader
myReader2 = File.OpenText(Server.MapPath("onlineUsers/onlineUsers.txt"))
Dim strCountValue2 as String
strCountValue2 = ""
while myReader2.Peek() <> - 1
strCountValue2 = strCountValue2 & myReader2.ReadLine()
End while
myReader2.Close()
Dim strInt1 as Integer
strInt1 = Convert.ToInt32(strCountValue2) - 1
Dim myWriter2 as StreamWriter
myWriter2 = File.CreateText(Server.MapPath("onlineUsers/onlineUsers.txt"))
myWriter2.Write(strInt1)
myWriter2.Close()
End Sub
Emile
Last edited by a moderator: