Accessing session within a class?

  • Thread starter Thread starter Gregory Pearce
  • Start date Start date
G

Gregory Pearce

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 :-)
 
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.
 
carion1 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top