Thread: Clear session

    #1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2006
    Posts
    558
    Rep Power
    12

    Clear session


    Hi,

    When I release session objects I do this
    Code:
    session("username")=""
    So whats the difference when I do this
    Code:
    set session("username")=nothing
    or
    session.remove("username")
    Isn't I already release it with a null value?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Posts
    1,882
    Rep Power
    19
    There is a slight different between destroying a session and making it equal to nothing.

    If it is equal to nothing then it does exist and use String or Len functions to compare/validate it.

    Logically, if you destroy the session then is doesnot exist and you should be able to use IsNull or IsEmpty to compare/validate.

    ASP VBScript is pretty lenient on some validation though.


    http://www.w3schools.com/asp/met_abandon.asp
    http://www.w3schools.com/asp/met_contents_remove.asp
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Location
    Sydney, Australia
    Posts
    50
    Rep Power
    12
    If you want to "destroy" all of your session variables you can also use:
    Code:
    Session.Abandon
    Hope this helps

    Alex
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2006
    Posts
    558
    Rep Power
    12
    Hello,

    I try to Stop IIS and when I Start it again sessions and application values are still there

    How do you clear all this objects in IIS? can I clear it in using IIS?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Location
    Bali - Indonesia
    Posts
    28
    Rep Power
    0
    hmm it sounds impossible dude when you restart IIS Then all user define variable will be released except cookies. it make a sense because those all variables exist under the IIS service.

    release session,

    if you using session("sesname") = "" mean
    you assign the session to have empty string value but the session variable still exist in the service.

    both set session("sesname")=nothing or session.remove("sesname") are quite same.

    session.abandon mean you destroy all session variables in your current service

    the best way to find out if the variables is exist or not by using isEmpty not isNull

    try these code:

    Code:
    <%
    ' I never declare the session("1") but isNull will return false
    
    Response.Write "isEmpty="&isEmpty(Session("1"))&"<br>"
    Response.Write "isNull="&isNull(Session("1"))&"<br>"
    %>
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2006
    Posts
    558
    Rep Power
    12
    Hi chazzuka,

    Oh I thought IIS can clear those objects, I guess not. Thanks!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Location
    Bali - Indonesia
    Posts
    28
    Rep Power
    0
    i mean when you stop the web service all the user define variables will be lost except cookies so i think it is impossible when u restart the IIS the the session still remain or maybe cache problem
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2006
    Posts
    558
    Rep Power
    12
    Hello,

    When I now use the clear session with a value set to nothing, I receive this error

    error
    Error Type:
    Session object, ASP 0185 (0x80020003)
    A default property was not found for the object.
    /logout.asp, line 2

    logout.asp
    Code:
    <%
    		session("id")=nothing
    		session("username")=nothing
    		session("islogin")=nothing	
    			
    		response.Redirect ("index.asp")
    %>
  16. #9
  17. Standing 3 feet to the left.
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2006
    Location
    USA
    Posts
    1,435
    Rep Power
    185
    It's my understanding that you have to use "Set" when doing that, like "Set session("id") = Nothing". Give that a shot.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2006
    Posts
    558
    Rep Power
    12
    Hi Tukaro,

    I have Set it and when I redirect it to another page I receive this error

    Error Type:
    Response object, ASP 0185 (0x80020003)
    A default property was not found for the object.
    /index.asp
    because there is no line number to know where the error is, I think this is where it cause it

    index.asp
    Code:
    .
    .
    .
    <%if isempty(session("islogin")) then%>
    .
    .
    .
    what went wrong?
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2006
    Posts
    558
    Rep Power
    12
    Hello,

    After setting to nothing in LOGOUT.asp from the above code how come I couldn't use this condition?
    Code:
    <%if isempty(session("islogin")) then
                     response.write "is empty"
                 else
                     response.write "empty" <--won't show :(
                 end if
    %>
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2007
    Location
    UK
    Posts
    5
    Rep Power
    0
    Have you tried:

    Session("id") = Empty

IMN logo majestic logo threadwatch logo seochat tools logo