Verify if Session(hashtable) exists

Discussion in 'ASP .Net' started by Carlos Albert, Dec 9, 2005.

  1. Hello everybody,

    I have SHOULD have a hashtable stored in a Session. How can I verify it such
    session really exists? I tried to use these sentences but ASP.NET doesn't
    like them, it says that session("hashtable") is not a string, or boolean...

    if session("hashtable") then ...

    if session("hashtable") <> "" then ...
     
    Carlos Albert, Dec 9, 2005
    #1
    1. Advertisements

  2. How about checking if the value is null?
     
    Peter Rilling, Dec 9, 2005
    #2
    1. Advertisements

  3. Carlos Albert

    addup Guest

    You can ennumerate the Session.Keys collection.
    Unfortunately it does not provide a "contains" function

    -- addup --
     
    addup, Dec 9, 2005
    #3
  4. Visual doesn't allow my to use is null (or System.DBNull for the case)...
    =(
     
    Carlos Albert, Dec 9, 2005
    #4
  5. Mhmm... and how could I just see if the session exists at all?
     
    Carlos Albert, Dec 9, 2005
    #5
  6. Oh, I found the way:

    Dim xx as hashtable = session("hashtable")
    if not xx is nothing then ...

    Tnx everybody =)
     
    Carlos Albert, Dec 9, 2005
    #6
  7. Didn't release you were using VB.NET. C# has "null" and VB.NET has
    "nothing".
     
    Peter Rilling, Dec 9, 2005
    #7
  8. LOL, my fault... thanks ^^

     
    Carlos Albert, Dec 12, 2005
    #8
  9. Carlos Albert

    addup Guest

    ah -- I must have misunderstood the question

    for VB.NET

    If HttpContext.Current.Session Is Nothing Then
     
    addup, Dec 14, 2005
    #9
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.