473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Session.Contents.Remove

YT
Howdy,

Why the heck wouldn't this work:

for each item in Session.Contents
if NOT( Instr( item, "customer_" ) = 1 OR Instr( item, "user_" ) = 1 ) Then
Session.Contents( item ) = ""
Session.Contents.Remove( item )
end if
next 'item

response.redirect( "menu.asp" )
the code essentially - is supposed to - go through the session variables and remove every one that doesn't being with "user_" or "customer_". So when i try this out, it goes through and removes some, but not all of the session variables in question. run the script 3 more times and then they are all gone. So i inserted a bunch of response.write statements and found that not ALL of the session variables were even being tested. Can anyone offer explanations as to why?

regards,
yt

Jul 19 '05 #1
1 3066
I ran into this one myself a week or two ago. I didn't bother looking up an
official bug report about this, but this is what I think happens:

When you delete an item from the contents collection, it re-ordens itself
automatically. If you delete item 8, item 9 becomes the new item 8, item 10
becomes item 9 etc. The For Each loop however doesn't seem to be adjusting
it's "index", and as it was done with item 8, it moves on to item 9, and
thus skipping the new item 8. Every time an item is deleted, the for each
misses a few items because the collection reorderns itself.

I fixed this by splitting up the variables to delete, and the actual
deletion in 2 runs.
In the first loop I record what items are to be deleted by storing them in
an array. In the second loop I run over my array, and delete each key I
stored in there.
That way everything gets deleted in a single try, and no items are skipped.
"YT" <yt******@MAPSONfunkychickens.org> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
Howdy,

Why the heck wouldn't this work:

for each item in Session.Contents
if NOT( Instr( item, "customer_" ) = 1 OR Instr( item, "user_" ) =
1 ) Then
Session.Contents( item ) = ""
Session.Contents.Remove( item )
end if
next 'item

response.redirect( "menu.asp" )
the code essentially - is supposed to - go through the session variables and
remove every one that doesn't being with "user_" or "customer_". So when i
try this out, it goes through and removes some, but not all of the session
variables in question. run the script 3 more times and then they are all
gone. So i inserted a bunch of response.write statements and found that not
ALL of the session variables were even being tested. Can anyone offer
explanations as to why?

regards,
yt

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Colin Steadman | last post by:
I have created a function to kill all session variables that aren't in a safe list. This is the function - Sub PurgeSessionVariables For Each Item In Session.Contents Select Case Trim(Item)...
1
by: Scott Lyon | last post by:
I'm maintaining (read: I didn't write it, nor do I have the time to spend to rewrite it) an application that is suddenly giving me grief. The reason I say suddenly, is because we're in the...
1
by: Dan King | last post by:
At a summary page, I am trying to clean up Session.Contents so the user can go back to the main page and not retain any unnecessary info. I have entered this into my summary page, but it seems to...
5
by: tshad | last post by:
When I log of I do: HttpContext.Current.Session.Clear() FormsAuthentication.SignOut() The problem is that it clears the variables that I set up in my Session_Start function in my...
4
by: Paul Rogers | last post by:
I have an existing .NET ( 1.1) application, and I ran Microsoft's FxCop on it, and it screamed at me about directly using textbox.text values instead of session values. So, I tried to re-write...
12
by: Anthony Jones | last post by:
Here's a question that I've not been able to get a definitive answer to. Creating an STA object (such as a typical VB6 object) and assigning to the ASP Session store is a bad thing. It's a bad...
11
by: Jerry | last post by:
I'm using this code: Dim strName For Each strName in Session.Contents Response.Write strName & " - " & Session.Contents(strName) & "<BR>" Next If I only do a response.write strName, it shows...
6
by: tshad | last post by:
Is there a reason to use session.remove over session.contents.remove? Don't they both remove the key and data from the contents collection? I assume that session(x) = nothing does essentially...
2
by: Lasse Edsvik | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.