By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,645 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,645 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
System.Web.HttpContext.Current.Session

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

"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:#P**************@TK2MSFTNGP10.phx.gbl...
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

Nov 18 '05 #2

P: n/a
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.
"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:#P**************@TK2MSFTNGP10.phx.gbl...
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?


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/groups?hl=e...phx.gbl&rnum=1

Hope this answers your question...

--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #3

P: n/a
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" <mb******@hotmail.com> wrote in message
news:Ou**************@tk2msftngp13.phx.gbl...
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.
"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:#P**************@TK2MSFTNGP10.phx.gbl...
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?

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/groups?hl=e...phx.gbl&rnum=1
Hope this answers your question...

--
Matt Berther
http://www.mattberther.com

Nov 18 '05 #4

P: n/a
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" <mb******@hotmail.com> wrote in message
news:Ou**************@tk2msftngp13.phx.gbl...
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.
"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:#P**************@TK2MSFTNGP10.phx.gbl...
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?

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/groups?hl=e...phx.gbl&rnum=1
Hope this answers your question...

--
Matt Berther
http://www.mattberther.com

Nov 18 '05 #5

P: n/a
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.

--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #6

P: n/a
That worked, thanks!
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
System.Web.HttpContext.Current.Session

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

"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:#P**************@TK2MSFTNGP10.phx.gbl...
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


Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.