473,385 Members | 1,356 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,385 software developers and data experts.

Detecting Session Timeout

Hi. How can I detect if a user's session has timed-out? I'd like to be able
to redirect the user to a specified page in the event of session timeout.

Thanks!
Oct 2 '06 #1
7 2032
You can't.

All you can do on the server, is when there is a request after the timeout,
you can detect it is a new session (either because your session variables
are empty, or because IsNewSession returns true), and redirect then.

Or you can have a countdown running on the client in javascript that
redirects.

The server however cannot know that the client has timed out and send a
redirect down.

"Mike" <Mi**@discussions.microsoft.comwrote in message
news:81**********************************@microsof t.com...
Hi. How can I detect if a user's session has timed-out? I'd like to be
able
to redirect the user to a specified page in the event of session timeout.

Thanks!

Oct 2 '06 #2
http://aspalliance.com/520

The ASP.NET HttpSessionState class provides a useful IsNewSession( ) method
that returns true if a new session was created for this request.

"Mike" <Mi**@discussions.microsoft.comwrote in message
news:81**********************************@microsof t.com...
Hi. How can I detect if a user's session has timed-out? I'd like to be
able
to redirect the user to a specified page in the event of session timeout.

Thanks!

Oct 2 '06 #3
I have seen some javascript client-side solutions. You may want to look in
the HTML of one of your online account providers, such as a bank or credit
card company, to see an example of a javascript timeout (usualy located in a
..js script file). Otherwise though, there's no real way to know when the
event occurs because the client and server are disconnected the second the
client retrieves the final item for that page.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"Mike" <Mi**@discussions.microsoft.comwrote in message
news:81**********************************@microsof t.com...
Hi. How can I detect if a user's session has timed-out? I'd like to be
able
to redirect the user to a specified page in the event of session timeout.

Thanks!

Oct 2 '06 #4
Thank you, both, very much!

"Mike" wrote:
Hi. How can I detect if a user's session has timed-out? I'd like to be able
to redirect the user to a specified page in the event of session timeout.

Thanks!
Oct 2 '06 #5
Forgive me if Im wrong but doe'nt the global.asax file have a Session_ONEND
event handler that you can use a redirect within?

Just a thought

Damian
MCP
Oct 4 '06 #6
Apologies for my silly remark about global.asax earlier, what you could do is
use this in your page header:

<meta http-equiv="refresh"
content="300;url='checksession.aspx?redirUrl=curre ntpage.aspx'">

So when the refresh occurs pass your current page across, check the session
state as in the following page load method:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Session("whatever") Then
Response.Redirect("loggedout.aspx")
Else
Response.Redirect(Request.QueryString("redirUrl"). ToString)
End If
End Sub

If it exists bounce them back to the original page, if not redirect to a
logged out page.

Thats what my banks uses by the look of it.

Easy Peasy.

Damian
MCP
Oct 4 '06 #7
Hi.

Doesn't the action of posting to checksession.aspx actually keep the
session itself alive, voiding the test to begin with?
DieHardGuy wrote:
<meta http-equiv="refresh"
content="300;url='checksession.aspx?redirUrl=curre ntpage.aspx'">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Session("whatever") Then
Response.Redirect("loggedout.aspx")
Else
Response.Redirect(Request.QueryString("redirUrl"). ToString)
End If
End Sub

If it exists bounce them back to the original page, if not redirect to a
logged out page.
Nov 9 '06 #8

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

Similar topics

4
by: DavidS | last post by:
First: There are several ways to confuse one regarding session timeout. (1) web.config - <sessionState timeout="20"> (2) IIS Manager | Internet Information Services | ServerNode | Default Web Site...
4
by: Chris | last post by:
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...
3
by: Simon | last post by:
Hi all, Any help with this would be much appreciated: I have a site where the session needs to timeout because of security concerns. I want to send the user back to the login page if the...
11
by: Vishal | last post by:
Hello, can anybody tell me how I can extend the session expiry time? Is it done via code or via IIS? Sorry I am new and dont know about this.
4
by: Chris Newby | last post by:
I realize that I can handle "SessionEnd" from global.asax ... but it appears to me that this gets called without the context of a current web request. So given the following scenario: User logs...
4
by: UJ | last post by:
I have a page where the user can upload a video file. As you can guess, this may take a while. Is there a way I can change the session timeout for just this one page? I would also want to change...
2
by: runner7 | last post by:
Can anyone tell me if there is a way in PHP to determine when a session times out on the server or how many concurrent sessions there are in your application?
9
by: timor.super | last post by:
Hi group, I've written a client/server application, using the dotnet sockets. In my server, I have a thread waiting for messages with : ret = currSocket.Receive(buffer, 1024,...
3
by: Sems | last post by:
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.