471,339 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

Accessing session information from another project in a solution

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
Jul 21 '05 #1
2 3402
"Mike Grace" wrote:
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

- - -

Jul 21 '05 #2
Thank you.

Regards

Mike

"Steven Spits" <no****@company.com> wrote in message
news:Oi**************@tk2msftngp13.phx.gbl...
"Mike Grace" wrote:
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

- - -

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by AARON PECORARO | last post: by
5 posts views Thread by Michelle A. | last post: by
4 posts views Thread by Cowboy \(Gregory A. Beamer\) | last post: by
4 posts views Thread by Charles | last post: by
5 posts views Thread by Ryan | last post: by
4 posts views Thread by Nick Gilbert | last post: by
8 posts views Thread by GaryDean | last post: by

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.