PC Review


Reply
Thread Tools Rate Thread

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

 
 
Kevin Spencer
Guest
Posts: n/a
 
      22nd Apr 2004
System.Web.HttpContext.Current.Session

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

"Charlie@CBFC" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Matt Berther
Guest
Posts: n/a
 
      22nd Apr 2004
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" <(E-Mail Removed)> wrote in message
> news:#(E-Mail Removed)...
>
>> 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
 
Reply With Quote
 
Charlie@CBFC
Guest
Posts: n/a
 
      22nd Apr 2004
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


 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      22nd Apr 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> > news:#(E-Mail Removed)...
> >
> >> 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



 
Reply With Quote
 
Matt Berther
Guest
Posts: n/a
 
      22nd Apr 2004
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
 
Reply With Quote
 
Charlie@CBFC
Guest
Posts: n/a
 
      22nd Apr 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> > news:#(E-Mail Removed)...
> >
> >> 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



 
Reply With Quote
 
Charlie@CBFC
Guest
Posts: n/a
 
      23rd Apr 2004
That worked, thanks!
"Kevin Spencer" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> System.Web.HttpContext.Current.Session
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Big things are made up
> of lots of little things.
>
> "Charlie@CBFC" <(E-Mail Removed)> wrote in message
> news:#(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Inherit an internal class to a public class guiroux22@gmail.com Microsoft C# .NET 4 27th Aug 2007 07:43 PM
Can it possible redefine class with subclass when inherit base class with sub class? ABC Microsoft C# .NET 4 10th Jan 2006 11:13 PM
Web service class, inherit from asmx class free.teranews.com Microsoft Dot NET 1 18th Feb 2005 12:31 AM
Web service class, inherit from asmx class free.teranews.com Microsoft C# .NET 1 18th Feb 2005 12:31 AM
inherit from class which inherits from Page class djus@poczta.onet.pl Microsoft ASP .NET 0 14th Jul 2004 01:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:11 PM.