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

  • Thread starter Thread starter Kevin Spencer
  • Start date Start date
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.
 
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...
 
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
 
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.
 
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.
 
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.
 
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.
 
Back
Top