Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Releasing Session Variables

    How do you release a session variable so it no longer exists.

    Ive tried setting them to null, nothing and vbempty, the variable is empty but an instance of it is still there. I need to completely remove any trace of the session variable so it wil not be picked up using the following code

    Dim x
    dim session_list

    for x = 1 to session.Contents.Count

    session_list = session_list & "|" & Session.Contents.Key(x) & "~" & Session.Contents.Item(x)

    next

    Response.Write(session_list)

    I thought this would be a simple procedure but I cant find any resources on the net to do this.

    Any help would be greatly appreciated.

    Thanks

    Steve.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    why not use something like this:
    Code:
    <%
    Dim sessitem
    For Each sessitem in Session.Contents
      if session.Contents(sessitem) <> "" then
         Response.write(sessitem & " : " & Session.Contents(sessitem) & "<BR>")
       end if
    Next 
    %>
    -->inserting a condition to filter out the empty ones from the collection.

    Setting them to nothing clears the space that the session-variable used, but doesn't remove it from the session collection because it has session scope it (since it doesn't take up space, why bother ?). Session object can only be destroyed by using abandon or when session terminates.


    ------------------
    More info from helpfile:

    To create an object with session or application scope, you can either use the <OBJECT> tag and set the SCOPE attribute to SESSION or APPLICATION, or store the object in a session or application variable.

    For example, an object stored in a session variable, as shown in the following script, is destroyed when the Session object is destroyed. That is, when the session times out, or the Abandon method is called.

    <% Set Session("ad") = Server.CreateObject("MSWC.AdRotator")%>

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    London
    Posts
    179
    Thanks
    0
    Thanked 0 Times in 0 Posts

    This should do it

    Hi steveg

    To completely remove the session variable itself you have to use the REMOVE method

    If you're just looking to remove one session variable then the code would be:

    Code:
    Session.Contents.Remove("VarName")
    If you want to remove all session variables, for instance on a logout event, then use this...

    Code:
    Session.Contents.RemoveAll
    Session.Abandon
    Let me know if that works.

    dominicall
    dominicall - confusing himself more and more each day


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •