473,804 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Session Object is Null in Page Load

Here's my code:

private void Page_Load(objec t sender, System.EventArg s e)
{
clientId = Session["clientId"].ToString();
.... etc.

It bombs on the assignment after the session has timed out
(System.NullRef erenceException : 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(objec t sender, System.EventArg s e)
{
if (Session["clientId"]==null)
{
Response.Redire ct("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 2510
Have you tried putting the following line in Global.asax under
Session_Start?

Session.Add("cl ientID","");


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

to this
if ( String.IsEmptyO rNull( Session["clientId"] ) ) {
do you have sure that you assign the session("Client Id") 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******** *************** ***********@mic rosoft.com...
Here's my code:

private void Page_Load(objec t sender, System.EventArg s e)
{
clientId = Session["clientId"].ToString();
... etc.

It bombs on the assignment after the session has timed out
(System.NullRef erenceException : 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(objec t sender, System.EventArg s e)
{
if (Session["clientId"]==null)
{
Response.Redire ct("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("cl ientID","");


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

to this
if ( String.IsEmptyO rNull( Session["clientId"] ) ) {
do you have sure that you assign the session("Client Id") 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******** *************** ***********@mic rosoft.com...
Here's my code:

private void Page_Load(objec t sender, System.EventArg s e)
{
clientId = Session["clientId"].ToString();
... etc.

It bombs on the assignment after the session has timed out
(System.NullRef erenceException : 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(objec t sender, System.EventArg s e)
{
if (Session["clientId"]==null)
{
Response.Redire ct("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(objec t sender, System.EventArg s e)
{
clientId = Session["clientId"].ToString();
... etc.

It bombs on the assignment after the session has timed out
(System.NullRef erenceException : 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(objec t sender, System.EventArg s e)
{
if (Session["clientId"]==null)
{
Response.Redire ct("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
5452
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 if i click a link $_SERVER returns the value I want and the session id. Any ideas as to how I can get the $_SERVER to return the arguments on first page load?
5
10857
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
2433
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 XmlTextReader("http://localhost/page.aspx")); } The requested page (page.aspx) is an XHTML page so I'm able to parse it as a
2
2295
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 In the current release of our system, we decided to "wrap" the ASP.NET Session and Application objects to improve code clarity and accuracy. For example, instead of: Session = new SomeListClass;
3
1765
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 OnLoad event is fired on each page load and then the specific Page_Load event of the specific page. But whenever the OnLoad event in the base class is fired the Session object
3
1668
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 (Page.IsValid) { MyXferObj obj = new MyXferObj();
2
960
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 object this way. I was certain that this worked previously??? Unfortunately is VS i am getting the error, 'System.Web.UI.Page cannot be
6
2092
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 of the ViewState being too large. I'm trying to avoid writing manual paging routines for now. -- Tim
3
3360
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
0
9711
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
10595
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...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
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
9169
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...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
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
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.