Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > getting a Session under a Class

Reply
Thread Tools

getting a Session under a Class

 
 
Bruno Alexandre
Guest
Posts: n/a
 
      06-13-2006
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)




 
Reply With Quote
 
 
 
 
Marina Levit [MVP]
Guest
Posts: n/a
 
      06-13-2006
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)
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Timeout problems-web.confg session state and IIS session s =?Utf-8?B?Um9iSEs=?= ASP .Net 4 04-11-2007 04:52 PM
Getting class to compile under JDK 1.5 AND 1.6 Chris Java 8 12-14-2006 02:56 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Session State - What does it take to establish one single ASP.NET session per "browser session" Jeff Smythe ASP .Net 3 01-02-2004 04:10 AM
How can I "know" the difference between a session timed out and a session that did session.abort? Jazzis ASP General 2 09-23-2003 07:16 AM



Advertisments