Accessing session data in a class file- which class do I inherit from?

K

Kevin Spencer

System.Web.HttpContext.Current.Session

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
M

Matt Berther

Hello Kevin,
System.Web.HttpContext.Current.Session

Actually, this is the property that he should use. For what he's doing, he has no need to inherit from a class.

I've posted some code to this group before detailing a singleton implementation of a Session wrapper. Using this code would allow you to use Session state in whatever class you want.

Take a look at http://groups.google.com/[email protected]&rnum=1

Hope this answers your question...
 
C

Charlie@CBFC

Hi:

The code to add items to shopping cart is a seperate class file so I don't
have to keep repeating it. If I want to be able to access session data in
this class, which class should I base it on?

Thanks,
Charlie
 
K

Kevin Spencer

Inherit from a class?! What I posted was nothing but a static property of
the System.Web.HttpContext class. No inheritance involved. Simply a complete
namespace. No wrapper necessary. A wrapper just adds useless overhead.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Matt Berther said:
Hello Kevin,


Actually, this is the property that he should use. For what he's doing, he
has no need to inherit from a class.
I've posted some code to this group before detailing a singleton
implementation of a Session wrapper. Using this code would allow you to use
Session state in whatever class you want.
 
M

Matt Berther

Hello Kevin,
Inherit from a class?! What I posted was nothing but a static property
of the System.Web.HttpContext class. No inheritance involved. Simply a

I understand. You have the right answer. However, he was asking about inheriting from a class.
complete namespace. No wrapper necessary. A wrapper just adds useless
overhead.

I would disagree with your comment about the wrapper. The code that I posted gives me strongly typed access to my session variables, which is much better for catching errors at compile time.
 
C

Charlie@CBFC

It would not work using base class- got errors trying to access session
vars. I then derived it from Page class and it works fine. Just wondering
if there is a more lightweight class?

Charlie

Matt Berther said:
Hello Kevin,


Actually, this is the property that he should use. For what he's doing, he
has no need to inherit from a class.
I've posted some code to this group before detailing a singleton
implementation of a Session wrapper. Using this code would allow you to use
Session state in whatever class you want.
 
C

Charlie@CBFC

That worked, thanks!
Kevin Spencer said:
System.Web.HttpContext.Current.Session

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

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

Top