Accessing session information from another project in a solution

  • Thread starter Thread starter Mike Grace
  • Start date Start date
M

Mike Grace

Hi,

I have a session variable in an asp.net web project that I would like to
access from a C# project in the same solution.

When I try and use the Session variable e.g. acc =
Session["accountcode"]; in the C# project I get the following error:

C:\Inetpub\wwwroot\Optima Online\DataLibrary\DataClass.cs(272): The name
'Session' does not exist in the class or namespace 'DataLibrary.DataClass'


I have tried adding a "using System.Web.SessionState;" line to the file but
it doesn't make any difference.

Is this possible?


Mike
 
Mike Grace said:
I have a session variable in an asp.net web project that I would like to
access from a C# project in the same solution.

When I try and use the Session variable e.g. acc =
Session["accountcode"]; in the C# project I get the following error:

C:\Inetpub\wwwroot\Optima Online\DataLibrary\DataClass.cs(272): The name
'Session' does not exist in the class or namespace 'DataLibrary.DataClass'

Session (and Request, Response, etc) are properties of both Page and
UserControl. If you need to access them outside these classes, you should
use HttpContext.Current to get a reference:

using System.Web;

acc = HttpContext.Current.Session["accountcode"];

With kind regards,

Steven

- - -
 
Thank you.

Regards

Mike

Steven Spits said:
Mike Grace said:
I have a session variable in an asp.net web project that I would like to
access from a C# project in the same solution.

When I try and use the Session variable e.g. acc =
Session["accountcode"]; in the C# project I get the following error:

C:\Inetpub\wwwroot\Optima Online\DataLibrary\DataClass.cs(272): The name
'Session' does not exist in the class or namespace
'DataLibrary.DataClass'

Session (and Request, Response, etc) are properties of both Page and
UserControl. If you need to access them outside these classes, you should
use HttpContext.Current to get a reference:

using System.Web;

acc = HttpContext.Current.Session["accountcode"];

With kind regards,

Steven

- - -
 
Back
Top