getting a Session under a Class

Discussion in 'ASP .Net' started by Bruno Alexandre, Jun 13, 2006.

  1. Hi guys,

    I have a session called for example Portal, like session("Portal")

    and I want to retrieve that value inside a Class... how can I perfor such
    task?

    I thought it would like:

    Public Class Warranty
    Dim myPortalClass As Portal = HttpContext.Current.Session("Portal")

    but everytime I get here, I get an error saying
    System.NullReferenceException: Object reference not set to an instance of an
    object.

    but it's worng cause I have values in that session that I'm retriving
    correctly, the only problem is the use of the session variable inside the
    Class...

    How can I do this?

    --

    Bruno Alexandre
    (a Portuguese in Københanv, Danmark)
    Bruno Alexandre, Jun 13, 2006
    #1
    1. Advertising

  2. If that line is crashing, it means there is no current HttpContext
    available. If a session variable doesn't exist and you try to retrieve it,
    you would just get Nothing - you would not get an error.

    How and when are you calling this class to retrieve the values?

    Also, please always turn Option Strict On. I can tell you have it off,
    because that line wouldn't compile without a CType. Having it on generally
    finds a lot of errors at compile time rather then at runtime.

    "Bruno Alexandre" <> wrote in message
    news:...
    > Hi guys,
    >
    > I have a session called for example Portal, like session("Portal")
    >
    > and I want to retrieve that value inside a Class... how can I perfor such
    > task?
    >
    > I thought it would like:
    >
    > Public Class Warranty
    > Dim myPortalClass As Portal = HttpContext.Current.Session("Portal")
    >
    > but everytime I get here, I get an error saying
    > System.NullReferenceException: Object reference not set to an instance of
    > an object.
    >
    > but it's worng cause I have values in that session that I'm retriving
    > correctly, the only problem is the use of the session variable inside the
    > Class...
    >
    > How can I do this?
    >
    > --
    >
    > Bruno Alexandre
    > (a Portuguese in Københanv, Danmark)
    >
    >
    >
    >
    Marina Levit [MVP], Jun 13, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Smythe
    Replies:
    3
    Views:
    1,230
    Jeff Smythe
    Jan 2, 2004
  2. E11
    Replies:
    1
    Views:
    4,720
    Thomas Weidenfeller
    Oct 12, 2005
  3. Chris
    Replies:
    8
    Views:
    852
    Thomas Hawtin
    Dec 14, 2006
  4. =?Utf-8?B?Um9iSEs=?=
    Replies:
    4
    Views:
    5,254
    =?Utf-8?B?Um9iSEs=?=
    Apr 11, 2007
  5. Jazzis
    Replies:
    2
    Views:
    235
    Jazzis
    Sep 23, 2003
Loading...

Share This Page