473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 17477
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: | last post by:
Hi, I want to do things this way: I have a bunch of stuff that I want to keep track of while a user is connected to the site. Maybe 50 little peices of information. So I know I can make 50...
2
by: Reena | last post by:
Hi, I am working on .NET 2003, C#. I have created a class file and getting... The name 'Session' does not exist in the class or namespace 'RADWebV5.RADAsp.Class.Connection' Connection.cs...
14
by: Paul Yanzick | last post by:
Hello, I am trying to develop a book tracking application for my capstone in school, and am running into a problem. The application is an ASP.Net application written in C#. The first page you...
1
by: Scott Chang | last post by:
Hi all, I loaded the following program 'HelloMCPP' to my MS VC++ .NET (2002) that is installed on my Windows XP Professional PC: ------------------------------------- AssemblyInfo.cpp...
8
by: MattB | last post by:
Hello I am starting a new thread in a button click event. This thread calls an method which sends emails, I don't want the page to wait for the emails to finish going out as it slows the user...
5
by: Filip | last post by:
Hello, (ASP.NET c#) I want to put some common functions into one class and within this class I need to have access to the Session, Request and Response. This class is not page behind file! I...
2
by: George | last post by:
Hi In my ASP.NET project, I have a session variable that is assigned on a login page. In another .cs file (in another directory), I'm trying to use if((string)Session == "something" When I...
2
by: Dave | last post by:
Hello. I have created some class and want to access session data, but there is error message: The name 'Session' does not exist in the class or namespace 'MyApp.MyWebApp.MyClass'. So how can...
4
by: Robert E. Flaherty | last post by:
Working with ASP.NET 1.1 - C# I have been attempting to locate all of reading and writing of session variables into a class in its own file. The file contains: using System; using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.