Session.contents.remove problem

Posted on 2003-03-05
Medium Priority
Last Modified: 2011-10-03
Hello everybody.

I am experiencing a wierd problem with Session.contents.remove while attempting to remove several variants. Here is my code:

For Each strName in Session.Contents
     if Left(strName, 8) = "histemp_" then
     end if

I have 105 session variants starting with "histemp_", and EVERYTIME I call this function, it removes the 57 first variants, and thereafter continue the loop without doing it. If I use the Session.Contents(strName) = "", it works well, so I think that Remove is the problem...

Has anybody ever experienced this problem and found a solution ?

By the way, I am using win2K server SP3 with IIS5 and no .Net framework, and I know using a lot of Session variants is bad :)
Question by:HMax
  • 2

Author Comment

ID: 8071157
Oh and I don't want to use Session.Abandon, I just want to remove the specified session variants.

Accepted Solution

wslogue earned 200 total points
ID: 8071285
Hi HMax,

here's the problem. As you remove session variables, the list that you're cycling through is getting shorter but, at the same time, you're still moving forward through it.

When you remove an item from a collection, the list gets shorter and all following items effectively move down a place with the next item filling the space of the item that you've just removed.

It's a bit like pulling all Frank Sinatra CDs out of a big pile stacked up on your desk. The 10th one up is a Sinatra CD so you swiftly pull it out and the rest of the stack drops down. But you're then MOVING UP to the 11th one - what if the NEW 10th one up is also a Sinatra CD.

To solve this problem, you should whizz backwards though the list. Something like (forgive any bad syntax)

for i=Session.Contents.Count to 1 step -1
    if Left( Session.Contents(i), 8).....
    end if

Hope this helps.


Author Comment

ID: 8071326
This work perfectly and was very instructive. Thx a ton!

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question