Session bug

L

Lasse Edsvik

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
 
E

Evertjan.

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
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top