473,375 Members | 1,669 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,375 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 17473
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.