471,325 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

'Session' does not exist in the class or namespace ....

I inherited some code from someone, and I am trying to use Session to store
some information that I need. For some reason, I can see that in another
file, the previous developer used Session["blahblah"] and assigned it to a
value, but when I try and do the same thing in a different part of the code,
(in a different namespace, if that helps), I get a compilation error, saying
that it doesn't exist.

I am using VS .NET 2003 and when I bring up the other file, I can mouse over
the Session object and see that it is a
System.Web.SessionState.HttpSessionState UserControl.Session object. But,
when I go to the file that I am trying to edit, when I mouse over it, it is
unrecognized. It thinks I'm trying to use a variable called Session, instead
of using the system one. Does anybody have any idea why this is happening?

Brian
Feb 13 '06 #1
3 17292
The class / assembly will need to have a reference set to System.Web.
Then you can access the current Session object with:

HttpContext.Current.Session

Hope that helps.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"brian" wrote:
I inherited some code from someone, and I am trying to use Session to store
some information that I need. For some reason, I can see that in another
file, the previous developer used Session["blahblah"] and assigned it to a
value, but when I try and do the same thing in a different part of the code,
(in a different namespace, if that helps), I get a compilation error, saying
that it doesn't exist.

I am using VS .NET 2003 and when I bring up the other file, I can mouse over
the Session object and see that it is a
System.Web.SessionState.HttpSessionState UserControl.Session object. But,
when I go to the file that I am trying to edit, when I mouse over it, it is
unrecognized. It thinks I'm trying to use a variable called Session, instead
of using the system one. Does anybody have any idea why this is happening?

Brian

Feb 13 '06 #2
Context.Session["blahblah"] = "You shouldn't be doing this anyway";

--

Derek Davis
dd******@gmail.com

"brian" <br***@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
I inherited some code from someone, and I am trying to use Session to store
some information that I need. For some reason, I can see that in another
file, the previous developer used Session["blahblah"] and assigned it to a
value, but when I try and do the same thing in a different part of the
code,
(in a different namespace, if that helps), I get a compilation error,
saying
that it doesn't exist.

I am using VS .NET 2003 and when I bring up the other file, I can mouse
over
the Session object and see that it is a
System.Web.SessionState.HttpSessionState UserControl.Session object. But,
when I go to the file that I am trying to edit, when I mouse over it, it
is
unrecognized. It thinks I'm trying to use a variable called Session,
instead
of using the system one. Does anybody have any idea why this is
happening?

Brian

Feb 14 '06 #3
> I inherited some code from someone, and I am trying to use Session to store
some information that I need. For some reason, I can see that in another
file, the previous developer used Session["blahblah"] and assigned it to a
value, but when I try and do the same thing in a different part of the code,
(in a different namespace, if that helps), I get a compilation error, saying
that it doesn't exist.

I am using VS .NET 2003 and when I bring up the other file, I can mouse over
the Session object and see that it is a
System.Web.SessionState.HttpSessionState UserControl.Session object. But,
when I go to the file that I am trying to edit, when I mouse over it, it is
unrecognized. It thinks I'm trying to use a variable called Session, instead
of using the system one. Does anybody have any idea why this is happening?

Brian


The "Session" property that a usercontrol has, is not some magical
"system variable", but just a regular property of the (base class of
the) user control.

From within a different class, you can access the Session using
System.Web.HttpContext.Current.Session. Watch out: this will only work
if there *is* a "current httpcontext", that is, if the call to this
method is the result of some Request. If this method is called from a
timer event for instance, then HttpContext.Current is null.

Hans Kesting
Feb 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Reena | last post: by
14 posts views Thread by Paul Yanzick | last post: by
8 posts views Thread by MattB | last post: by
2 posts views Thread by George | last post: by
2 posts views Thread by Dave | last post: by
4 posts views Thread by Robert E. Flaherty | 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.