473,406 Members | 2,217 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,406 software developers and data experts.

Detecting loss of session

When a request comes into a page on my ASP.net site and a session is
not found, I want to detect whether the request is an initial request
or if the user did have a session going that has now been lost and
show an explanatory message before restarting the session.

Rather than tagging a 'session in progress' flag on the end of every
request querystring I'd like to detect it using data sent in every
request.

One idea I had was that when a browser expecting a session sends a
sessionId cookie that no longer matches a stored session in IIS, this
indicates a lost session.

Am I right in thinking that looking for the sessionId cookie is
reliable way to detect the loss of a session and is there a better way
that will work seemlessly for cookieless sessions as well?
Nov 18 '05 #1
4 2735
look at the Session_onStart in the Global.asax file to catch the session
starting.
As for if it's a "new" one or not, you really can't.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Chris" <fr*******@surf.to> wrote in message
news:57**************************@posting.google.c om...
When a request comes into a page on my ASP.net site and a session is
not found, I want to detect whether the request is an initial request
or if the user did have a session going that has now been lost and
show an explanatory message before restarting the session.

Rather than tagging a 'session in progress' flag on the end of every
request querystring I'd like to detect it using data sent in every
request.

One idea I had was that when a browser expecting a session sends a
sessionId cookie that no longer matches a stored session in IIS, this
indicates a lost session.

Am I right in thinking that looking for the sessionId cookie is
reliable way to detect the loss of a session and is there a better way
that will work seemlessly for cookieless sessions as well?

Nov 18 '05 #2
Hi Chris,

I believe you could indeed store the SessionID in a Cookie. If the current
SessionID is not the same as the Cookie, the user has started a new Session.
If the Cookie is not present, the user has not been there before. However,
the problem is going to be getting rid of the Cookie. For example, if the
user starts a Session, which sets the Cookie, closes his/her browser, and
comes back 2 hours later, the Cookie will have a SessionID in it, and it
will not match the current SessionID. But in this case, the user's Session
has not been interrupted.

Perhaps you should rethink this problem in terms of requirements. There may
be a better way to achieve what your requirements dictate.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Chris" <fr*******@surf.to> wrote in message
news:57**************************@posting.google.c om...
When a request comes into a page on my ASP.net site and a session is
not found, I want to detect whether the request is an initial request
or if the user did have a session going that has now been lost and
show an explanatory message before restarting the session.

Rather than tagging a 'session in progress' flag on the end of every
request querystring I'd like to detect it using data sent in every
request.

One idea I had was that when a browser expecting a session sends a
sessionId cookie that no longer matches a stored session in IIS, this
indicates a lost session.

Am I right in thinking that looking for the sessionId cookie is
reliable way to detect the loss of a session and is there a better way
that will work seemlessly for cookieless sessions as well?

Nov 18 '05 #3
Kevin,

I was thinking of a session cookie so that from the browsers
perspective that cookie will exist so long as the browser isn't
closed, even if something happens on the server that looses the
session such a timeout.

If the the browser is closed then the cookie in gone and the session
should rightly be ended and a new one started when the user next sends
a request. From what I've read on session cookies (no expiry set?)
this might not work with all browsers because they delete (or stop
sending) them as soon as they expire, not when the browser is closed?

Brad - How does your user control work? I want to put the code in a
base page class that all other pages on the site derive from but I
might be able to do something similar.

Thanks all.

"Kevin Spencer" <ks******@takempis.com> wrote in message news:<eS*************@TK2MSFTNGP11.phx.gbl>...
Hi Chris,

I believe you could indeed store the SessionID in a Cookie. If the current
SessionID is not the same as the Cookie, the user has started a new Session.
If the Cookie is not present, the user has not been there before. However,
the problem is going to be getting rid of the Cookie. For example, if the
user starts a Session, which sets the Cookie, closes his/her browser, and
comes back 2 hours later, the Cookie will have a SessionID in it, and it
will not match the current SessionID. But in this case, the user's Session
has not been interrupted.

Perhaps you should rethink this problem in terms of requirements. There may
be a better way to achieve what your requirements dictate.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Chris" <fr*******@surf.to> wrote in message
news:57**************************@posting.google.c om...
When a request comes into a page on my ASP.net site and a session is
not found, I want to detect whether the request is an initial request
or if the user did have a session going that has now been lost and
show an explanatory message before restarting the session.

Rather than tagging a 'session in progress' flag on the end of every
request querystring I'd like to detect it using data sent in every
request.

One idea I had was that when a browser expecting a session sends a
sessionId cookie that no longer matches a stored session in IIS, this
indicates a lost session.

Am I right in thinking that looking for the sessionId cookie is
reliable way to detect the loss of a session and is there a better way
that will work seemlessly for cookieless sessions as well?

Nov 18 '05 #4
> If the the browser is closed then the cookie in gone and the session
should rightly be ended and a new one started when the user next sends
a request. From what I've read on session cookies (no expiry set?)
this might not work with all browsers because they delete (or stop
sending) them as soon as they expire, not when the browser is closed?
That's a good question, Chris. If you don't set the expiration on a Cookie,
it expires at the end of the browser Session. However, you may have heard
right (I don't know) that some browsers may delete Session Cookies when the
browser navigates away from a domain (although I haven't heard of it),
rather than when the browser closes. It would be worth investigating.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Chris" <fr*******@surf.to> wrote in message
news:57*************************@posting.google.co m... Kevin,

I was thinking of a session cookie so that from the browsers
perspective that cookie will exist so long as the browser isn't
closed, even if something happens on the server that looses the
session such a timeout.

If the the browser is closed then the cookie in gone and the session
should rightly be ended and a new one started when the user next sends
a request. From what I've read on session cookies (no expiry set?)
this might not work with all browsers because they delete (or stop
sending) them as soon as they expire, not when the browser is closed?

Brad - How does your user control work? I want to put the code in a
base page class that all other pages on the site derive from but I
might be able to do something similar.

Thanks all.

"Kevin Spencer" <ks******@takempis.com> wrote in message

news:<eS*************@TK2MSFTNGP11.phx.gbl>...
Hi Chris,

I believe you could indeed store the SessionID in a Cookie. If the current SessionID is not the same as the Cookie, the user has started a new Session. If the Cookie is not present, the user has not been there before. However, the problem is going to be getting rid of the Cookie. For example, if the user starts a Session, which sets the Cookie, closes his/her browser, and comes back 2 hours later, the Cookie will have a SessionID in it, and it
will not match the current SessionID. But in this case, the user's Session has not been interrupted.

Perhaps you should rethink this problem in terms of requirements. There may be a better way to achieve what your requirements dictate.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Chris" <fr*******@surf.to> wrote in message
news:57**************************@posting.google.c om...
When a request comes into a page on my ASP.net site and a session is
not found, I want to detect whether the request is an initial request
or if the user did have a session going that has now been lost and
show an explanatory message before restarting the session.

Rather than tagging a 'session in progress' flag on the end of every
request querystring I'd like to detect it using data sent in every
request.

One idea I had was that when a browser expecting a session sends a
sessionId cookie that no longer matches a stored session in IIS, this
indicates a lost session.

Am I right in thinking that looking for the sessionId cookie is
reliable way to detect the loss of a session and is there a better way
that will work seemlessly for cookieless sessions as well?

Nov 18 '05 #5

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

Similar topics

0
by: Si | last post by:
Hi there. I am developing a shopping cart that writes shopping basket contents to a temp DB with a temp reference of the sessionID to identify the 'owner' of the basket. My question is, when...
1
by: db_guy | last post by:
Hi, we have a php-based application that is hosted by Yahoo! Webhosting. Ever since the application was created, it has been plagued by periodic session data loss. Here's a typical example: We...
4
by: John Wilcher | last post by:
Environment: Windows 2000 Server, IIS 5.0, ASP .Net Framework 1.1, VB .Net source code We are experiencing a condition that manifests itself as a loss of all session objects. Intermittently...
14
by: Michael Carr | last post by:
I have an intermittent problem that occurs on a very small number of browsers that access my website. The strange thing is this: my site works perfectly for 99.9% of browsers. The behavior...
2
by: ASP.Confused | last post by:
How would I go about detecting a memory leak? My web hosting provider has our site set up to only have a root "bin" folder for .NET apps, and I would like to be able to watch how much memory is...
8
by: Tim W. | last post by:
Chaps. We are working with SQL-Server based Sessions in the following environemtn: Win-Server 2K3 incl. IIS, Dot Net Framework 1.1, SQL2K SP3a, German. We are defining a Session-Variable...
5
by: John | last post by:
I've started to get session loss on many of my web apps, after only a few minutes (the session lifespan is supposed to be 60 minutes). It occurs in several apps (all on same server), and started...
4
by: leena13 | last post by:
Hi, I am facing a problem of loss of session variables once the ASP.Net 2.0 application is deployed. Let me add that this is actually a 1.1 to 2.0 migration. I found that the first time the...
3
by: Martin Kulov [MVP] | last post by:
Hi, I am wondering if this problem is still valid for ASP.NET 2.0. "To maintain session state across different Web servers in the Web farm, the application path of the Web site (for example,...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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
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,...
0
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...

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.