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 :-)
 
***************
using System;
using System.Web; //also make sure add a reference "System.Web.DLL" in your
Project class

namespace tClass
{
public class Class1
{
public Class1()
{
doSession("mySession");
}

private void doSession(string sessionKey)
{
string
mySessionData=(string)HttpContext.Current.Session[sessionKey];
}
}
}

*************
John Webb
 
This line can retrieve an integer value from the current session:

int myInt =
Convert.ToInt32(System.Web.HttpContext.Current.Session["myIntVariableName"]);


-HTH
 

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