473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

getting a Session under a Class

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)


Jun 13 '06 #1
1 906
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" <br*********@gmail.com> wrote in message
news:ed**************@TK2MSFTNGP03.phx.gbl...
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)

Jun 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ronchese | last post by:
I'm noticing this since I started developing a website project: my session variables are getting empty! I did a real easy test, and I checked my session variable is getting empty!! What is...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
3
by: tshad | last post by:
I have a file that I converted from VB.Net to C# that works fine in VB.Net when I compile but not in C# using the same libraries. The error I am getting is: PageInit.cs(9,7): error CS0138: A...
2
by: sony.m.2007 | last post by:
Hi, When i try to set a value for a session variable I'm getting a object refence not set error I tried two methods as below HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.