Lasse Edsvik wrote on 25 sep 2007 in
microsoft.public.inetserver.asp.general:
Hello
I have a problem with running classic asp on a windows 2003 server.
For some reason it doesnt remove the sessions. I reload page and it
removes some, reload again and it removes a few more, very odd...
Any ideas? :S im clueless
For each key In Session.Contents()
If instr(key, "Question") >0 Then
Session.Contents.Remove(key)
Response.Write(key & ":" & Session(key) & "<br>")
End If
Next
When you remove a session variable, the position changes and
"For each key In" will skip those positions and:
try and see what happens when you repeatedly press F5 on this asp file:
<%
Session("one") = 1
Session("two") = 2
Session("three") = 3
Session("Zone") = 1
Session("Ztwo") = 2
Session("Zthree") = 3
For Each Item in Session.Contents
Response.Write Item & "=" & Session.Contents(Item) & "<BR>"
Next
Response.Write "<hr>"
For Each Item in Session.Contents
Session.Contents.Remove(Item)
Response.Write Item & "=" & Session.Contents(Item) & "<BR>"
Next
%>
So better do this:
<%
Session("one") = 1
Session("two") = 2
Session("three") = 3
Session("Zone") = 1
Session("Ztwo") = 2
Session("Zthree") = 3
For Each Item in Session.Contents
Response.Write Item & "=" & Session.Contents(Item) & "<BR>"
Next
Response.Write "<hr>"
Session.Contents.RemoveAll()
For Each Item in Session.Contents
Response.Write Item & "=" & Session.Contents(Item) & "<BR>"
Next
%>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)