Session problem

G

Guest

hi,
I am anand.I used session state object in some pages in my application ex
Session("UserId").

some times applications displayed the following error

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
pos.TopBanner.Page_Load(Object sender, EventArgs e)
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Page.ProcessRequestMain() +772


how to rectify the error?
regards
anand
 
H

Hans Kesting

hi,
I am anand.I used session state object in some pages in my application ex
Session("UserId").

some times applications displayed the following error

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
pos.TopBanner.Page_Load(Object sender, EventArgs e)
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Page.ProcessRequestMain() +772

how to rectify the error?
regards
anand

You didn't specify the source where the error occurred, so it is not
clear to me that it has anything to do with that Session object. But
that /is/ possible.

The error means that you try to use some reference as if it is pointing
to a real instance of a class, but (at this time) it isn't pointing
anywhere (it's null).

Your crash *can* occur in a place where you try to use that session
object, if that object doesn't exist (yet). Say you are trying to use
that object before the person has logged in (causing that userid to be
set).

Solutions:
1) carefully review your application: are you trying to use that
session object before it is filled?
2) check that it really exists before using it. In C#:
if (Session["userid"] != null) ...

Hans Kesting
 
G

Guest

Hi, check if the session is not null before working with it.
if session("userid") isnot nothing then
.....
end if

Have you checked your session timeout value?.
---------------------------
Thanks,
Ibrahim

Software Consultant - Web Development, GB


Hans Kesting said:
hi,
I am anand.I used session state object in some pages in my application ex
Session("UserId").

some times applications displayed the following error

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
pos.TopBanner.Page_Load(Object sender, EventArgs e)
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Page.ProcessRequestMain() +772

how to rectify the error?
regards
anand

You didn't specify the source where the error occurred, so it is not
clear to me that it has anything to do with that Session object. But
that /is/ possible.

The error means that you try to use some reference as if it is pointing
to a real instance of a class, but (at this time) it isn't pointing
anywhere (it's null).

Your crash *can* occur in a place where you try to use that session
object, if that object doesn't exist (yet). Say you are trying to use
that object before the person has logged in (causing that userid to be
set).

Solutions:
1) carefully review your application: are you trying to use that
session object before it is filled?
2) check that it really exists before using it. In C#:
if (Session["userid"] != null) ...

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top