473,499 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What causes session to disappear?

In my asp.net 2.0 web application, in Web.config, I have

timeout="30", s l i d i n g E x p i r a t i o n = "true"

for the Authentication element. I suppose, this means that as long as
we don't let a 30 min elapse without making any request, the session
should stay alive, right?

But I notice that quite often, the application throws out Null
reference exception where I try to access a session variable like so:

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

Apparently, the session variable is lost.

I am sure it is way before a 30 minutes' elapse without making any
request.

Question:

1. Do we lose the session if the project gets JIT-recompiled?

2. Do we lose the session if an Exception happens?

Thank you.

Jan 18 '08 #1
7 5221
Anytime the IIS application is restarted, all sessions are restarted too.
So yes, this would generally happen during recompilations and some major
unhandled application level exceptions.

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
http://iPhonePlaza.net

"gnewsgroup" <gn********@gmail.comwrote in message
news:f0**********************************@e23g2000 prf.googlegroups.com...
In my asp.net 2.0 web application, in Web.config, I have

timeout="30", s l i d i n g E x p i r a t i o n = "true"

for the Authentication element. I suppose, this means that as long as
we don't let a 30 min elapse without making any request, the session
should stay alive, right?

But I notice that quite often, the application throws out Null
reference exception where I try to access a session variable like so:

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

Apparently, the session variable is lost.

I am sure it is way before a 30 minutes' elapse without making any
request.

Question:

1. Do we lose the session if the project gets JIT-recompiled?

2. Do we lose the session if an Exception happens?

Thank you.
Jan 18 '08 #2

"gnewsgroup" <gn********@gmail.comwrote in message
news:f0**********************************@e23g2000 prf.googlegroups.com...
In my asp.net 2.0 web application, in Web.config, I have

timeout="30", s l i d i n g E x p i r a t i o n = "true"

for the Authentication element. I suppose, this means that as long as
we don't let a 30 min elapse without making any request, the session
should stay alive, right?

But I notice that quite often, the application throws out Null
reference exception where I try to access a session variable like so:

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

Apparently, the session variable is lost.

I am sure it is way before a 30 minutes' elapse without making any
request.

Question:

1. Do we lose the session if the project gets JIT-recompiled?

2. Do we lose the session if an Exception happens?

Thank you.
I think the answer depends on the session-state "Mode" of your web app.
Assuming it's "in-proc" (the default) then modifying web.config or a DLL in
the "bin" directory will do it. As will restarting the application pool
(either manually, or automatically due to memory limits, cpu utilization,
etc.).

You might try switching to StateServer or SQLServer mode, but you will need
to ensure that you only put value types and serializable objects into the
session if you do that.

In general, you should always verify the existence of a session object
before trying to use it - and handle the case where it doesn't exist.

Jan 18 '08 #3
An application domain will unload (causing loss of session variables
unless session state is maintained with State Server or SQL Server),
when any one of the following occurs:

a. Machine.Config, Web.Config or Global.asax are modified
b. The bin directory or any of its contents is/are modified
c. The App_Code directory contents changes
d. The number of re-compilations (aspx, ascx or asax) exceeds the limit specified by the
<compilation numRecompilesBeforeAppRestart=/setting in machine.config or web.config
(by default this is set to 15)
e. The physical path of the virtual directory is modified
f. The CAS policy is modified
g. A web service is restarted
h. (2.0 only) Application Sub-Directories are deleted
i. Any of a number of configurable App Pool recycling reasons occurs

This should cover most scenarios.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Scott Roberts" <sr******@no.spam.here-webworks-software.comwrote in message
news:e3**************@TK2MSFTNGP05.phx.gbl...
>
"gnewsgroup" <gn********@gmail.comwrote in message
news:f0**********************************@e23g2000 prf.googlegroups.com...
>In my asp.net 2.0 web application, in Web.config, I have

timeout="30", s l i d i n g E x p i r a t i o n = "true"

for the Authentication element. I suppose, this means that as long as
we don't let a 30 min elapse without making any request, the session
should stay alive, right?

But I notice that quite often, the application throws out Null
reference exception where I try to access a session variable like so:

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

Apparently, the session variable is lost.

I am sure it is way before a 30 minutes' elapse without making any
request.

Question:

1. Do we lose the session if the project gets JIT-recompiled?

2. Do we lose the session if an Exception happens?

Thank you.

I think the answer depends on the session-state "Mode" of your web app. Assuming it's "in-proc" (the default) then
modifying web.config or a DLL in the "bin" directory will do it. As will restarting the application pool (either
manually, or automatically due to memory limits, cpu utilization, etc.).

You might try switching to StateServer or SQLServer mode, but you will need to ensure that you only put value types
and serializable objects into the session if you do that.

In general, you should always verify the existence of a session object before trying to use it - and handle the case
where it doesn't exist.


Jan 19 '08 #4
On Jan 18, 5:28 pm, "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]"
<St...@Orr.netwrote:
Anytime the IIS application is restarted, all sessions are restarted too.
So yes, this would generally happen during recompilations and some major
unhandled application level exceptions.

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsiderhttp://SteveOrr.nethttp://iPhonePlaza.net
First of all, Steve, thank you so much, and I just found your
marvelous ExportPanel yesterday and have put it into my code. Really
nice and neat. Thanks for sharing your wonderful work for free.

Now back to this thread topic. I also notice that the session does
not always disappear when an exception happens. Is it possible to
predict what type of exception will cause the session to disappear?
Jan 19 '08 #5
On Jan 18, 5:28 pm, "Steve C. Orr [MCSD, MVP, CSM, ASP Insider]"
<St...@Orr.netwrote:
Anytime the IIS application is restarted, all sessions are restarted too.
So yes, this would generally happen during recompilations and some major
unhandled application level exceptions.

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsiderhttp://SteveOrr.nethttp://iPhonePlaza.net
Is it possible to predict what type of exception will cause the
session to disappear? Or does M$ has a list of Exception types that
will cause session to disappear?

BTW, I found your cool ExportPanel just yesterday and have put it into
my web application. Really nice and neat. Thanks for sharing your
wonderful work for free.
Jan 19 '08 #6
On Jan 18, 6:01 pm, "Scott Roberts" <srobe...@no.spam.here-webworks-
software.comwrote:
"gnewsgroup" <gnewsgr...@gmail.comwrote in message

news:f0**********************************@e23g2000 prf.googlegroups.com...
In my asp.net 2.0 web application, in Web.config, I have
timeout="30", s l i d i n g E x p i r a t i o n = "true"
for the Authentication element. I suppose, this means that as long as
we don't let a 30 min elapse without making any request, the session
should stay alive, right?
But I notice that quite often, the application throws out Null
reference exception where I try to access a session variable like so:
System.NullReferenceException: Object reference not set to an instance
of an object.
Apparently, the session variable is lost.
I am sure it is way before a 30 minutes' elapse without making any
request.
Question:
1. Do we lose the session if the project gets JIT-recompiled?
2. Do we lose the session if an Exception happens?
Thank you.

I think the answer depends on the session-state "Mode" of your web app.
Assuming it's "in-proc" (the default) then modifying web.config or a DLL in
the "bin" directory will do it. As will restarting the application pool
(either manually, or automatically due to memory limits, cpu utilization,
etc.).

You might try switching to StateServer or SQLServer mode, but you will need
to ensure that you only put value types and serializable objects into the
session if you do that.

In general, you should always verify the existence of a session object
before trying to use it - and handle the case where it doesn't exist.
That brings up a question which I have always been wondering. So you
suggest that we should always do something like:

if ( Session.Contents["MySessionVariable"] != null)
{
// Do things with MySessionVariable
}
else
{
// Do something else, maybe including logout a user if some
critical
// session variables such as "UserName" is missing.
}

before we use that session variable? That's a lot of if-else's if we
use quite many session variables.
Jan 19 '08 #7
On Jan 18, 7:36 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:
An application domain will unload (causing loss of session variables
unless session state is maintained with State Server or SQL Server),
when any one of the following occurs:

a. Machine.Config, Web.Config or Global.asax are modified
b. The bin directory or any of its contents is/are modified
c. The App_Code directory contents changes
d. The number of re-compilations (aspx, ascx or asax) exceeds the limit specified by the
<compilation numRecompilesBeforeAppRestart=/setting in machine.config or web.config
(by default this is set to 15)
e. The physical path of the virtual directory is modified
f. The CAS policy is modified
g. A web service is restarted
h. (2.0 only) Application Sub-Directories are deleted
i. Any of a number of configurable App Pool recycling reasons occurs

This should cover most scenarios.

Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en español :http://asp.net.do/foros/
======================================"Scott Roberts" <srobe...@no.spam.here-webworks-software.comwrote in message
Fantastic, I never know about this. Your list of situations are
certainly enough to explain why my sessions are mysteriously missing.
Thank you.
Jan 19 '08 #8

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

Similar topics

6
6552
by: Ruben van Engelenburg | last post by:
Hi all, I have a strange problem. I have a login procedure that uses a mysql database in which the users are stored. The login procedure is pretty straightforward. In every page I unclude my...
5
2559
by: Ben | last post by:
Hello, My $_SESSION variables disappear and reappear. It's not just a matter of not caching the page. I usually have to press the Refresh button about 3 times to get the page to remember the...
220
18799
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
5
4008
by: Larry Woods | last post by:
I am losing Session variables, but only those that are set in the page previous to a redirect to a secure page. Anyone seen ANY situation where Session variables just "disappear?" Note that...
6
3884
by: Nicolae Fieraru | last post by:
Hi All, I recently discovered that my session cookies on the web host disappear within 30 seconds. I created some very simple asp scripts (it took me a while until I discovered why my shopping...
6
1609
by: Jon | last post by:
If a session times out, but the forms auth is still logged in it's possible for users to go to pages on the site that need those session variables. I was under the impression that using forms auth...
3
1175
by: Lucas Tam | last post by:
Does recompiling cause session objects to disappear? -- Lucas Tam (REMOVEnntp@rogers.com) Please delete "REMOVE" from the e-mail address when replying....
5
3060
by: Simon | last post by:
Hi all, We have a small problem. We are running an ASP.NET1.1 application, using IIS6 on server2003, no web farm, on a single server, using in-proc session state, only using one worker...
2
3951
by: HLady | last post by:
I have a sequence of clicks in my apps that are always causing the session to start again. This is definitely not being caused by a timeout, cause it always happens no matter how long since the...
0
7131
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,...
0
7174
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,...
0
7220
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...
1
6894
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...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4919
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...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
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...

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.