473,385 Members | 1,661 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.

Session Object is Null in Page Load

Here's my code:

private void Page_Load(object sender, System.EventArgs e)
{
clientId = Session["clientId"].ToString();
.... etc.

It bombs on the assignment after the session has timed out
(System.NullReferenceException: Object reference not set to an instance of an
object). I don't understand why it is processing the page load event at all.
It should already have redirected, shouldn't it?

if I modify the code to do the redirection, it does not help and I get a 404:

private void Page_Load(object sender, System.EventArgs e)
{
if (Session["clientId"]==null)
{
Response.Redirect("Login.aspx",true);
}
}

The mechanism seems to be magical. I cannot debug it. Anyone any clue
what's going on?

TIA,
Jeb.


Jun 7 '06 #1
3 2478
Have you tried putting the following line in Global.asax under
Session_Start?

Session.Add("clientID","");


Bruno Alexandre wrote:
change this
if (Session["clientId"]==null)

to this
if ( String.IsEmptyOrNull( Session["clientId"] ) ) {
do you have sure that you assign the session("ClientId") before getting into
that page? So you can avoid the error...

--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
"JebBushell" <jebbushell AT yahoo DOT com> escreveu na mensagem
news:A3**********************************@microsof t.com...
Here's my code:

private void Page_Load(object sender, System.EventArgs e)
{
clientId = Session["clientId"].ToString();
... etc.

It bombs on the assignment after the session has timed out
(System.NullReferenceException: Object reference not set to an instanceof
an
object). I don't understand why it is processing the page load event at
all.
It should already have redirected, shouldn't it?

if I modify the code to do the redirection, it does not help and I get a
404:

private void Page_Load(object sender, System.EventArgs e)
{
if (Session["clientId"]==null)
{
Response.Redirect("Login.aspx",true);
}
}

The mechanism seems to be magical. I cannot debug it. Anyone any clue
what's going on?

TIA,
Jeb.


Jun 7 '06 #2
Have you tried putting the following line in Global.asax under
Session_Start?

Session.Add("clientID","");


Bruno Alexandre wrote:
change this
if (Session["clientId"]==null)

to this
if ( String.IsEmptyOrNull( Session["clientId"] ) ) {
do you have sure that you assign the session("ClientId") before getting into
that page? So you can avoid the error...

--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)
"JebBushell" <jebbushell AT yahoo DOT com> escreveu na mensagem
news:A3**********************************@microsof t.com...
Here's my code:

private void Page_Load(object sender, System.EventArgs e)
{
clientId = Session["clientId"].ToString();
... etc.

It bombs on the assignment after the session has timed out
(System.NullReferenceException: Object reference not set to an instanceof
an
object). I don't understand why it is processing the page load event at
all.
It should already have redirected, shouldn't it?

if I modify the code to do the redirection, it does not help and I get a
404:

private void Page_Load(object sender, System.EventArgs e)
{
if (Session["clientId"]==null)
{
Response.Redirect("Login.aspx",true);
}
}

The mechanism seems to be magical. I cannot debug it. Anyone any clue
what's going on?

TIA,
Jeb.


Jun 7 '06 #3
There are two timeouts in my web.config file, one for session and another for
authentication. It seems that if the session times out before the
authentication then I get the problem. If this is the complete
explanation, then it seems like it's a standard Gotcha, and you might expect
to see warnings in documentation. Maybe I missed them?

"JebBushell" wrote:
Here's my code:

private void Page_Load(object sender, System.EventArgs e)
{
clientId = Session["clientId"].ToString();
... etc.

It bombs on the assignment after the session has timed out
(System.NullReferenceException: Object reference not set to an instance of an
object). I don't understand why it is processing the page load event at all.
It should already have redirected, shouldn't it?

if I modify the code to do the redirection, it does not help and I get a 404:

private void Page_Load(object sender, System.EventArgs e)
{
if (Session["clientId"]==null)
{
Response.Redirect("Login.aspx",true);
}
}

The mechanism seems to be magical. I cannot debug it. Anyone any clue
what's going on?

TIA,
Jeb.

Jun 8 '06 #4

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

Similar topics

6
by: user | last post by:
when i first load index.php with arguments ie: "index.php?page=x", the $_SERVERvalue is null. I then get the session id appended to each link. If i refresh the page, I get the $_SERVER I want, but...
5
by: LL | last post by:
Hi, Where is the best place to check the session's object, if it's null, then redirect the user to login page? put into every page's load event? Thanks.
3
by: Peter Theill | last post by:
Hi, I'm trying to include the content of a request into an Xml document: if (System.Web.HttpContext.Current.Session != null) { XmlDocument d = new XmlDocument(); d.Load(new...
2
by: John Mullin | last post by:
We are having a problem which appears similar to a previous posting: http://groups.google.com/groups?hl=en&lr=&frame=right&th=d97f552e10f8c94c&seekm=OZw33z9EDHA.2312%40TK2MSFTNGP10.phx.gbl#link1 ...
3
by: Frank Esser | last post by:
Hi, I created a base class for my project from that all other pages inherit. Within this page in the OnLoad event I set some session object variables. My intention is that first of all the...
3
by: ESmith | last post by:
I have multi-page form where I pass an object between pages as follows: On each page: // What page to go to next private void btnContinue_Click(object sender, System.EventArgs e) { if...
2
by: Adam J Knight | last post by:
Hi all, I have just migrated a project from Web Matrix to VS. The project contains a class which retrieves values in the Session object. I am attempting to retrieve an instance of the Session...
6
by: AAOMTim | last post by:
I have a large ViewState and I've heard I can save the ViewState in a sesison object. What are the advantages of doing so and how do I do it? I've been told that I am gettign DNS timeouts because...
3
by: Jan Kucera | last post by:
Hi, why is session object null if the ashx file is requested? How can I force to create session when the request is to custom handler? Thanks, Jan
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: 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:
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
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...

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.