473,806 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpContext.Cur rent.Session==n ull in .cs file

Hello,
I have created ASP.NET project in which I have a file Admin.cs. It contains
static class Admin with some methods and properties. The problem is that in
property get a reference HttpContext.Cur rent.Session is null, although for
instance HttpContext.Cur rent.Applicatio n or HttpContext.Cur rent.Request is
not null:
public static class Admin

{

...

set

{

HttpContext.Cur rent.Session["Database"] = value; // HERE OK

}

get

{

object db = HttpContext.Cur rent.Session["Database"]; // HERE PROBLEM

if (db == null)

return null;

return db.ToString();

}

...

}

Could anyone explain me why? How to use Session object in my code?
/RAM/
Oct 15 '07 #1
14 29485
R.A.M. wrote:
Hello,
I have created ASP.NET project in which I have a file Admin.cs. It contains
static class Admin with some methods and properties. The problem is that in
property get a reference HttpContext.Cur rent.Session is null, although for
instance HttpContext.Cur rent.Applicatio n or HttpContext.Cur rent.Request is
not null:
public static class Admin

{

...

set

{

HttpContext.Cur rent.Session["Database"] = value; // HERE OK

}

get

{

object db = HttpContext.Cur rent.Session["Database"]; // HERE PROBLEM

if (db == null)

return null;

return db.ToString();

}

...

}

Could anyone explain me why? How to use Session object in my code?
/RAM/

Have you debugged the code and verified that it's actually the reference
to the Session object that is null, and not simply that the Items
collection doesn't contain the key "Database"?

--
Göran Andersson
_____
http://www.guffa.com
Oct 15 '07 #2
Uzytkownik "Göran Andersson" <gu***@guffa.co mnapisal w wiadomosci
news:un******** ******@TK2MSFTN GP05.phx.gbl...
Have you debugged the code and verified that it's actually the reference
to the Session object that is null, and not simply that the Items
collection doesn't contain the key "Database"?
Yes, I debugged the code. HttpContext.Cur rent.Applicatio n,
HttpContext.Cur rent.Cache, HttpContext.Cur rent.Response,
HttpContext.Cur rent.Request are not null, they reference valid object. Only
HttpContext.Cur rent.Session is null.
It looks strange for me, so I have sent the post.
Could you help me?
/RAM/
Oct 15 '07 #3
I have forgotten to add: I changed web server from IIS 5.1 to Cassini 2.
Generally Cassini works fine, but maybe that's the reson why Session doesn't
work... I cannot use IIS because I had interal error in IIS and I failed to
solve the problem.
/RAM/
Oct 15 '07 #4
U¿ytkownik "R.A.M." <r_********@poc zta.onet.plnapi sa³ w wiadomo¶ci
news:fe******** **@news2.task.g da.pl...
>I have forgotten to add: I changed web server from IIS 5.1 to Cassini 2.
Generally Cassini works fine, but maybe that's the reson why Session
doesn't work... I cannot use IIS because I had interal error in IIS and I
failed to solve the problem.
No, that's not the reson. I have learnt that Cassini supports Session
object.
/RAM/
Oct 15 '07 #5
R.A.M. wrote:
Uzytkownik "Göran Andersson" <gu***@guffa.co mnapisal w wiadomosci
news:un******** ******@TK2MSFTN GP05.phx.gbl...
>Have you debugged the code and verified that it's actually the reference
to the Session object that is null, and not simply that the Items
collection doesn't contain the key "Database"?

Yes, I debugged the code. HttpContext.Cur rent.Applicatio n,
HttpContext.Cur rent.Cache, HttpContext.Cur rent.Response,
HttpContext.Cur rent.Request are not null, they reference valid object. Only
HttpContext.Cur rent.Session is null.
It looks strange for me, so I have sent the post.
Could you help me?
/RAM/
In your code you indicated that the Session object existed when you set
the session variable, but not when you read it? It doesn't make sense
that the existance of the Session object would be different depending on
if you try to read or write a value. Where do you use the property? When
does the Session object exist?

The web site can have session state enabled or disabled, but that is a
global setting for the site. If disabled, there won't be any Session
objects at all.

--
Göran Andersson
_____
http://www.guffa.com
Oct 15 '07 #6
I have learnt that accessibilty of HttpContext.Cur rent.Session may depend on
the place I use Admin...get.
But in my project it is Default.aspx page (startup), method Page_Load
(code-behind). So I have a question: should HttpContext.Cur rent.Session be
accessible in this place?
/RAM/
Oct 15 '07 #7
Uzytkownik "Göran Andersson" <gu***@guffa.co mnapisal w wiadomosci
news:%2******** ************@TK 2MSFTNGP02.phx. gbl...
In your code you indicated that the Session object existed when you set
the session variable, but not when you read it? It doesn't make sense that
the existance of the Session object would be different depending on if you
try to read or write a value. Where do you use the property? When does the
Session object exist?
I use set/get in code-behind of Default.aspx.
The web site can have session state enabled or disabled, but that is a
global setting for the site. If disabled, there won't be any Session
objects at all.
I have session enabled in my web.config:
<sessionState mode="InProc" timeout="20" />
Oct 16 '07 #8
R.A.M. wrote:
Uzytkownik "Göran Andersson" <gu***@guffa.co mnapisal w wiadomosci
news:%2******** ************@TK 2MSFTNGP02.phx. gbl...
>In your code you indicated that the Session object existed when you set
the session variable, but not when you read it? It doesn't make sense that
the existance of the Session object would be different depending on if you
try to read or write a value. Where do you use the property? When does the
Session object exist?
I use set/get in code-behind of Default.aspx.
When does the Session object exist?
>The web site can have session state enabled or disabled, but that is a
global setting for the site. If disabled, there won't be any Session
objects at all.
I have session enabled in my web.config:
<sessionState mode="InProc" timeout="20" />
If the session state is disabled in IIS, the setting in web.config
doesn't have any effect.

--
Göran Andersson
_____
http://www.guffa.com
Oct 16 '07 #9
R.A.M. wrote:
I have learnt that accessibilty of HttpContext.Cur rent.Session may depend on
the place I use Admin...get.
There is only a HttpContext if the code is executed to handle a request.
The Application_End event for example is not executed to handle a
request, and doesn't have a HttpContext.
But in my project it is Default.aspx page (startup), method Page_Load
(code-behind). So I have a question: should HttpContext.Cur rent.Session be
accessible in this place?
Yes. If session state is enabled for the site.

--
Göran Andersson
_____
http://www.guffa.com
Oct 16 '07 #10

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

Similar topics

0
2573
by: Spam sucks | last post by:
Hello, Could somebody explane me how i can read a session file and unserialize it and read the array that is created. **script for reading session files** function getUsersOnline() { $count = 0; $ses_dir=get_cfg_var('session.save_path'); $handle = opendir('/tmp');
1
1820
by: C-man | last post by:
Basically I have this little program that will look through directories and rename any file it finds. The renaming that takes place is like removing of dashes or Caps the first letter from each word and so on. Is there a better way to rename the files instead of creating a new file and calling originalFile.renameTo(new File(newFilename)); Basically I want to know if creating this new File each time will be costly in both memory and time...
1
3704
by: Eranga Udesh | last post by:
Hi All, In my ASP file, located at the "/test" directory of the website, I include another ASP file as below. <!--#include file="../templates/_header.asp"--> Inside the _header.asp file, how can I get the current file (_header.asp) directory? I need to get the web relative/absolute directory of _header.asp, but instead even if I can get the physical directory location of that file
2
4315
by: Luis Esteban Valencia Muñoz | last post by:
I have a 2 base classes that do error handling -- one for pages (System.Web.UI.Page) and one for applications (System.Web.HttpApplication, Global.asax uses it). Are there any situations in either of these error handlers where HttpContext.Current would be null? Page Error Handler public class PageBase : System.Web.UI.Page {
3
1954
by: KK | last post by:
How to get the current file name in vb.net. For example. I am executing a method in vb.net dll say 'xyz.dll" I want to use the filename 'xyz.dll' in side the method. any ideas? Thanks
4
1519
by: parez | last post by:
Hi all, HttpContext.Current is null in my webeventprovider. Why would that be? I am using a customwebbaseevent. Please Help. Thanks inadvance.
1
1755
by: Lastknight | last post by:
hello all, can some bidy suggest me how to code for this problem? how to write a perl program using Apache::Session::File module? regards lastknight..
7
3151
by: pmstel | last post by:
How can I compile to a .pyc the current file by putting the command in the tool menu of Python??
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10623
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10373
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9192
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4330
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 we have to send another system
2
3852
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.