PC Review


Reply
Thread Tools Rate Thread

Accessing session within a class?

 
 
Gregory Pearce
Guest
Posts: n/a
 
      18th Sep 2005
Hi,
Can anyone tell me if it is possible to access a session within a class?
I have created a class that has

if ((Session["Books"] == null) etc....

However upon building the project, the name Session has a problem. I have
tried adding usingSystem.Web etc to the class however cannot seem to rectify
the problem.

Any ideas anyone?

Many thanks for everyone's help so far. I am still a bit new with C# and
really appreciate everyone's help :-)

Cheers - Greg :-)


 
Reply With Quote
 
 
 
 
Peter Rilling
Guest
Posts: n/a
 
      18th Sep 2005
Try something like HttpContext.Current.Session.


"Gregory Pearce" <(E-Mail Removed)> wrote
in message news:ZC2Xe.51342$(E-Mail Removed)...
> Hi,
> Can anyone tell me if it is possible to access a session within a class?
> I have created a class that has
>
> if ((Session["Books"] == null) etc....
>
> However upon building the project, the name Session has a problem. I have
> tried adding usingSystem.Web etc to the class however cannot seem to
> rectify the problem.
>
> Any ideas anyone?
>
> Many thanks for everyone's help so far. I am still a bit new with C# and
> really appreciate everyone's help :-)
>
> Cheers - Greg :-)
>
>



 
Reply With Quote
 
carion1
Guest
Posts: n/a
 
      18th Sep 2005
Context.Session["whatever"] is what you are looking for.

--

Derek Davis
(E-Mail Removed)

"Gregory Pearce" <(E-Mail Removed)> wrote
in message news:ZC2Xe.51342$(E-Mail Removed)...
> Hi,
> Can anyone tell me if it is possible to access a session within a class?
> I have created a class that has
>
> if ((Session["Books"] == null) etc....
>
> However upon building the project, the name Session has a problem. I have
> tried adding usingSystem.Web etc to the class however cannot seem to
> rectify the problem.
>
> Any ideas anyone?
>
> Many thanks for everyone's help so far. I am still a bit new with C# and
> really appreciate everyone's help :-)
>
> Cheers - Greg :-)
>
>



 
Reply With Quote
 
carion1
Guest
Posts: n/a
 
      18th Sep 2005
Just my opinion but I think you should stay away from this where possible.
Use properties or pass the data when you call the method that needs it.

--

Derek Davis
(E-Mail Removed)

"Gregory Pearce" <(E-Mail Removed)> wrote
in message news:ZC2Xe.51342$(E-Mail Removed)...
> Hi,
> Can anyone tell me if it is possible to access a session within a class?
> I have created a class that has
>
> if ((Session["Books"] == null) etc....
>
> However upon building the project, the name Session has a problem. I have
> tried adding usingSystem.Web etc to the class however cannot seem to
> rectify the problem.
>
> Any ideas anyone?
>
> Many thanks for everyone's help so far. I am still a bit new with C# and
> really appreciate everyone's help :-)
>
> Cheers - Greg :-)
>
>



 
Reply With Quote
 
Steve Walker
Guest
Posts: n/a
 
      19th Sep 2005
In message <#VB4hy$(E-Mail Removed)>, carion1
<(E-Mail Removed)> writes
>Just my opinion but I think you should stay away from this where possible.
>Use properties or pass the data when you call the method that needs it.


Doesn't seem unreasonable if the class is part of the UI, though. I'm
thinking custom webcontrols here. Otherwise, I agree, it's tying the
code in to running in process with the UI.

--
Steve Walker
 
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
Reflection.Emit accessing a field in the base class of a dynamically constructed class Douglas Harber Microsoft Dot NET Framework 0 11th Feb 2006 11:28 PM
Accessing Session variables when using SQL Server for Session state Michael Microsoft ASP .NET 3 30th Dec 2005 07:56 PM
Accessing session within a class Gregory Pearce Microsoft ASP .NET 2 18th Sep 2005 03:43 AM
Accessing Session variables from custom class =?Utf-8?B?bW9oeW5lZW5t?= Microsoft ASP .NET 2 8th Oct 2004 02:03 PM
Accessing session data in a class file- which class do I inherit from? Kevin Spencer Microsoft ASP .NET 6 23rd Apr 2004 12:32 AM


Features
 

Advertising
 

Newsgroups
 


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