473,796 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session.Content s.Remove

YT
Howdy,

Why the heck wouldn't this work:

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

response.redire ct( "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 3115
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******@MAPSO Nfunkychickens. org> wrote in message
news:OH******** ******@TK2MSFTN GP09.phx.gbl...
Howdy,

Why the heck wouldn't this work:

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

response.redire ct( "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
3472
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) Case "Authenticated" Case "CI_CODE" Case "organisation_description" Case "location_description"
1
2789
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 process of transitioning the server on which it runs from Microsoft Windows 2000 Server, to 2003 server (going from IIS 5 to IIS 6). This problem hasn't really occurred on the 2000 server machine, but it's happening MUCH more on the new 2003 box (not...
1
1626
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 only eliminate every other or every third entry. If I refresh the page about 0 times everything eventually clears out. Anyone know why it would do this? I don't want to use Session.Abandon because there are a few Session.Contents I want to...
5
22155
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 Global.asax file. One of the variables I set up is:
4
1330
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 parts of it using session variables and got no where. The (Pseudo) code that doesn't work at all is as follows: Page_Load( ) { if ( !IsPostBack )
12
2212
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 thing because it forces IIS to affiliate the Session with the Thread on which the STA object is created. This means all subsequent requests for that session can only be handled by that worker thread and can therefore result it in poor...
11
3727
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 all the session names but when I include the session.contents it gives me the following error:
6
7201
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 the same thing but is actually deleted later by the GC. Thanks, Tom
2
2023
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 more, very odd... Any ideas? :S im clueless For each key In Session.Contents()
0
9683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10457
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9054
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.