locked
How to clear all Session objects? RRS feed

  • Question

  • User805446595 posted

    I have about 50 session objects that I would like to clear/set to nothing.

    1. How can I get the name of my session object?

    2. How can I cycle through them at once?

    I think a For/Next will work fine, I am not sure of the syntax of the session object.

    I know I have 50 session objects.  I refer to them by a name in my code, though I found out that I can also refer to them by index number, but that doesnt give me the name of the object just the value.

    This is what I had in mind......but i know it doesnt work as written.

    I would also like to know the name of the session object:

    For i = 0 to Session.count

    Session(i)=nothing

    session(i).name

    Next

    Friday, September 2, 2011 3:51 PM

Answers

All replies

  • Friday, September 2, 2011 3:56 PM
  • User805446595 posted

    Is there a way to cycle through them 1 at a time?

    Session.Abondon will be good for my LogOut Procedure. Which I dont use at this point...but i need too.

    I am also looking to add something at login that will set certain session objects to false. I was hoping to be able to get the name based on the index number, but I dont see how i can.

    Friday, September 2, 2011 4:01 PM
  • User805446595 posted

    Also are there different levels of Session Objects? I know there are Application objects...I have about 15 Session objects that store User information (Name, Login, etc) Then each webpage might have 3-5 objects. Those 3-5 are usually used on another page as well.  Like Session("SaveMode") i use that on most of my pages.  Though Id like to clear it when the user leaves the page. 

    So i guess either I figure out what session objects I use on each page and do a cleanup function as part of Page_Unload Or is there some other type of variable I could use that is retained on postbacks?

    Personally, I think doing a cleanup would be easier to implement.

    Friday, September 2, 2011 4:10 PM
  • User805446595 posted

    Actually, Page_unload wouldnt work because that gets fired everytime.  I would need some event that is fired when changing pages....?

    Friday, September 2, 2011 4:13 PM
  • User-1404471107 posted

    foreach(string name in Session.Contents)
    {
        if(Session[name]!=null)
        {
         //name - gives you the session name
         //Session[name] - gives you the content

         //use "Session[name] = null" to clear the contents
        }
    }

    Monday, September 5, 2011 5:55 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 6, 2011 5:03 AM