473,467 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Access to Session from my class

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 access Sesstion from my custom class (class is in separate file,
not in web form)?
Nov 18 '05 #1
2 2003
Depending on the place in your code the session isn't available. For example
in the method Application_BeginRequest in Globals.asax.cs. In this case you
can try to find the session_id in a cookie:

String[] valCookie = Request.ServerVariables.GetValues("HTTP_COOKIE");
for (int i=0; i<valCookie.Length; i++) {
if (valCookie[i].ToUpper().StartsWith("ASP.NET_SESSIONID")) {
SessionId = valCookie[i].ToUpper().Replace("ASP.NET_SESSIONID=", "");
break;
}
}

"Dave" wrote:
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 access Sesstion from my custom class (class is in separate file,
not in web form)?

Nov 18 '05 #2
Dave wrote:
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 access Sesstion from my custom class (class is in separate
file, not in web form)?


use HttpContext.Current.Session

Note: will work only if you are really in an http-context, in other words your
call is a direct result of a request. (check first if HttpContext.Current is not null)
Hans Kesting
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: totierne | last post by:
comp.databases.ms-access, I want to know how to use Oracle views with session variables in Access. The parameterised views in access, are migrated to views with per session variables. The...
29
by: Patrick | last post by:
I have the following code, which regardless which works fine and logs to the EventViewer regardless of whether <processModel/> section of machine.config is set to username="SYSTEM" or "machine" ...
3
by: Wee Bubba | last post by:
i have a seperate class which i want to access the session state from. as a workaround i am able to access the session state by inheriting from the Page class. but this seems a waste as I dont need...
4
by: Kim Bach Petersen | last post by:
I would like to record user behavior data stored in session variables. Since the data is modified throughout each session it seemed obvious to store the data when the session terminates - using...
1
by: ward | last post by:
Good morning everyone. I'm building a very simple content management site that tracks "tasks." The options available are: 1. Add Task 2. Edit Task 3. View Task 4. Print Task
2
by: Corey B | last post by:
Is there a way for an instance of a custom class to access an ASPX page level variable? I know that I can access a Session variable from within a class using the following code: myClassVar =...
9
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service)...
0
by: bharathreddy | last post by:
Here I will given an example on how to access the session, application and querystring variables in an .cs class file. Using System.Web.HttpContext class. 1) For accesing session variables :...
4
by: Redivivus | last post by:
Hi How can i access Sessionstate from another class? Lets say i have webservice where i define Session=1; In my webservice project i have a common class. How can i access Session from this...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.