getting a Session under a Class

  • Thread starter Thread starter Bruno Alexandre
  • Start date Start date
B

Bruno Alexandre

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?
 
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.
 
Back
Top