Detecting a session timeout

S

Sems

Hi

I'm using the Session_End event in the global.asax to detect if a
users sessions has ended. Is there any way to tell if the session end
is due to it being expired and not abandoned?
I'm trying to show the user a popup if their session has expired due
to a timeout.

Whats the best way to do this?

Thanks
 
M

Michael Nemtsev

"HttpSessionState class's IsNewSession( ) method returns true if a new
session was created for a given request. If this is a new session but the
ASP.NET_SessionId cookie is present, this indicates a timeout situation"


Check the Peter article how to implement this check there
http://www.eggheadcafe.com/articles/20051228.asp
 
M

Mark Fitzpatrick

Instead of trying to handle it on the server, you may find it much easier to
handle on the client. I've seen this done at sites such as my bank, where
they warn me my session will end shortly unless I perform some action.

You can't really handle the popup server-side because the user may not even
be on the site anymore. Keep in mind, http is a stateless protocol and the
user is disconnected from the server the moment the browser finishes
requesting all the data for the page. That means there's really no user to
push data to such as a popup. Handling it on the client can be fairly easy
because you know how long the session timeout value is in minutes, and can
check that on the browser since the session will timeout at pretty much the
same time a script on the browser would determine that 20 minutes are up.
 
S

siccolo

Instead of trying to handle it on the server, you may find it much easier to
handle on the client. I've seen this done at sites such as my bank, where
they warn me my session will end shortly unless I perform some action.

You can't really handle the popup server-side because the user may not even
be on the site anymore. Keep in mind, http is a stateless protocol and the
user is disconnected from the server the moment the browser finishes
requesting all the data for the page. That means there's really no user to
push data to such as a popup. Handling it on the client can be fairly easy
because you know how long the session timeout value is in minutes, and can
check that on the browser since the session will timeout at pretty much the
same time a script on the browser would determine that 20 minutes are up.

--
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression









- Show quoted text -

for example, I do it like this (within ASPX page)
<!--
------------------------------------------------------------------------------------
-->
<!-- //for user session timeouts: -->
<!-- warn user session is about to expire in 1 min -->

<script type="text/javascript" language="javascript"
src="errors.js">
</script>
<script language="javascript" type="text/javascript">
function ShowTimeoutWarning ()
{
window.alert( "...about to expire..." );
window.location.href = "../Default.aspx";
}
<%
//Session.Timeout =2;
if ( HttpContext.Current.Session["UserSession"].ToString()!
=null )
{

Response.Write( "setTimeout('ShowTimeoutWarning();', " +
( Session.Timeout *
60000 ).ToString() + " );" );
}
%>
<!--
 
I

Ian Semmel

I don't think you can tell the user that the session has ended until
they actually do something on their browser.

In your Page_Load event (can be in a master page) you can do something
like

If ( Session.IsNewSession)
HttpContext.Current.Response.Redirect("/TimedOutPage.aspx");


The thing to remember is that by the time this has happened, the
previous session has been trashed so anything you are storing in
SessionState has gone. All you can tell the user is to log in again.
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top