getting a Session under a Class

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?
 
M

Marina Levit [MVP]

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top