473,385 Members | 2,004 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,385 software developers and data experts.

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 2000
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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:
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...

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.