473,471 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
6 1743
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jeremy Epstein | last post by:
I've got a 4-page form that lets users enter a whole lot of information, which is then submitted and emailed at the end. All the fields are stored as session data. The whole thing works fine: ...
6
by: Ravi Ambros Wallau | last post by:
Guys: Is there someway that allows a normal (and old) ASP page to access Session _or_ Application data of an ASP.NET page? I can't migrate this ASP page to ASP.NET. This ASP page loads an ISAPI...
4
by: Bruce Parker | last post by:
I have an executable that is launched by a custom action in the Windows Installer. Is there a way to get access to the Session variables (Global Properties)? Also how do I create a return code if...
2
by: Tom | last post by:
I hope someone can help me figure out what's going on here. I've re-read the section on sessions at php.net and Googled this high and low but I haven't found anything that quite explains my...
2
by: Sike | last post by:
Hi everyone, I've been browsing this and a few other related newsgroups trying to get my head around this problem, and so far all the trails seem to go cold, without an acceptable solution being...
5
by: Baeribeeri | last post by:
I am writing a foto upload site. A PHP page displays the uploades fotos an the customer can choose several things. The data of the fotos are kept in an array called bilder. I keep the data in a...
43
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
4
by: Joey | last post by:
asp.net 2/C#/VS2005 I have a web app where I use a stream writer to create a CSV (text) file. I then use my code to save the file in the site's 'App_Data' folder, in a subfolder called 'Temp'....
5
by: gom | last post by:
I am an amatuer asp.net programmer so I hope this question isn't to dumb. I am having difficulty with my understanding of session state. I have an application that stores some values in the...
5
by: Twayne | last post by:
Hi, If ever a newbie wants to know how much he has to learn yet, he only has to look here<g>!! ANYway: PHP 5.2.5; XP Pro SP2+, local Apache Server My actual question is: How do I get a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.