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

Go to Login Page when session expires

Hi all,
I was wondering how i could write some code which would automatically open
the Login Page once the session has expired?

--
Ad****@hotmail.com
Nov 19 '05 #1
12 6931
You can use the setTimeout javascript function for this.

<script language="javascript">
//this will call the javascript method _SessionExpired after 20 minutes

setTimeout( "_SessionExpired()", 20 * 60 * 1000 );

function _SessionExpired()
{
location.href = "login.aspx";
}
</script>

When 20 minutes has elapsed from the page opening the browser will be
redirected to the login page. Since you are going to be redirecting the
user you might want to give them a warning at say 19 minutes their session
is about to expire.

HTH,

bill

"ACaunter" <Ad****@hotmail.com> wrote in message
news:2C**********************************@microsof t.com...
Hi all,
I was wondering how i could write some code which would automatically open
the Login Page once the session has expired?

--
Ad****@hotmail.com

Nov 19 '05 #2
You can also put the following in Global.asax:

protected void Session_End(Object sender, EventArgs e)
{
Response.Redirect( "login.aspx" );
}

Nov 19 '05 #3
Neither that, nor the other solutions offered, will work.

When a session ends/expires, the server has no way
of knowing whether the user has already left the site
and is currently 10 sites away.


Juan T. Llibre
ASP.NET MVP
===========
"Stefan Kiryazov" <ch***@bulgaria.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
You can also put the following in Global.asax:

protected void Session_End(Object sender, EventArgs e)
{
Response.Redirect( "login.aspx" );
}

Nov 19 '05 #4
This will not work.

There is no HttpContext for the Session End event. This is a server side
only event.

bill

"Stefan Kiryazov" <ch***@bulgaria.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
You can also put the following in Global.asax:

protected void Session_End(Object sender, EventArgs e)
{
Response.Redirect( "login.aspx" );
}

Nov 19 '05 #5
I disagree. If the user leaves a page up (open) for the 20 minute Session
timeout, you can still direct them to another page. If the user has left
your site, you wouldn't want to redirect them to the login page, nor can
you.

He was asking about redirecting a user automatically when their Session
times out. Now the only hole in the solution offered is the Application
Restarts, the session will be new, but there is no way to notifiy the
browser.

bill

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Neither that, nor the other solutions offered, will work.

When a session ends/expires, the server has no way
of knowing whether the user has already left the site
and is currently 10 sites away.


Juan T. Llibre
ASP.NET MVP
===========
"Stefan Kiryazov" <ch***@bulgaria.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
You can also put the following in Global.asax:

protected void Session_End(Object sender, EventArgs e)
{
Response.Redirect( "login.aspx" );
}


Nov 19 '05 #6
re:
If the user leaves a page up (open) for the 20 minute
Session timeout, you can still direct them to another page.
Try it.

What you suggest will only enable Javascript redirection
after 20 minutes of inactivity in the page the JS script is in,
and is totally unrelated to the actual Session expiration/end.

What if the user has two windows open on your site,
and one of them is left open for the 20 minutes you
specify, but he is actively browsing the site in the other
window ( thereby keeping his Session alive ) ?

re: the only hole in the solution offered
is the Application Restarts
The Application won't restart only
because a User Session expires/ends.


Juan T. Llibre
ASP.NET MVP
===========
"William F. Robertson, Jr." <th****@nameht.org> wrote in message
news:uz**************@TK2MSFTNGP10.phx.gbl...I disagree. If the user leaves a page up (open) for the 20 minute Session
timeout, you can still direct them to another page. If the user has left
your site, you wouldn't want to redirect them to the login page, nor can
you.

He was asking about redirecting a user automatically when their Session
times out. Now the only hole in the solution offered is the Application
Restarts, the session will be new, but there is no way to notifiy the
browser.

bill

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Neither that, nor the other solutions offered, will work.

When a session ends/expires, the server has no way
of knowing whether the user has already left the site
and is currently 10 sites away.


Juan T. Llibre
ASP.NET MVP
===========
"Stefan Kiryazov" <ch***@bulgaria.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
> You can also put the following in Global.asax:
>
> protected void Session_End(Object sender, EventArgs e)
> {
> Response.Redirect( "login.aspx" );
> }

Nov 19 '05 #7
ACaunter--
So in short, this is impossible to achieve completely.

Juan--
Ahhh. I had not thought about the new window, same session scenario.

What I suggested was to set his javascript redirection timeout the same as
the server. Unless of course asp.net ignores the SessionTimeout settings
and just randomly times out Sessions. In which case it wouldn't work.
The Application won't restart only
because a User Session expires/ends.
Ofcourse not, but the Application restart will cause all of the Sessions to
be recreated on next postback. Thus they will be ended.

bill
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... re:
If the user leaves a page up (open) for the 20 minute
Session timeout, you can still direct them to another page.


Try it.

What you suggest will only enable Javascript redirection
after 20 minutes of inactivity in the page the JS script is in,
and is totally unrelated to the actual Session expiration/end.

What if the user has two windows open on your site,
and one of them is left open for the 20 minutes you
specify, but he is actively browsing the site in the other
window ( thereby keeping his Session alive ) ?

re:
the only hole in the solution offered
is the Application Restarts


The Application won't restart only
because a User Session expires/ends.


Juan T. Llibre
ASP.NET MVP
===========
"William F. Robertson, Jr." <th****@nameht.org> wrote in message
news:uz**************@TK2MSFTNGP10.phx.gbl...
I disagree. If the user leaves a page up (open) for the 20 minute Session timeout, you can still direct them to another page. If the user has left your site, you wouldn't want to redirect them to the login page, nor can
you.

He was asking about redirecting a user automatically when their Session
times out. Now the only hole in the solution offered is the Application
Restarts, the session will be new, but there is no way to notifiy the
browser.

bill

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Neither that, nor the other solutions offered, will work.

When a session ends/expires, the server has no way
of knowing whether the user has already left the site
and is currently 10 sites away.


Juan T. Llibre
ASP.NET MVP
===========
"Stefan Kiryazov" <ch***@bulgaria.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
> You can also put the following in Global.asax:
>
> protected void Session_End(Object sender, EventArgs e)
> {
> Response.Redirect( "login.aspx" );
> }


Nov 19 '05 #8
re:
Unless of course asp.net ignores the
SessionTimeout settings and just
randomly times out Sessions.
Very early versions of ASP had that sort of hiccup.

ASP.NET has improved the
handling of Session data quite a lot.

re: What I suggested was to set his javascript
redirection timeout the same as the server.
The problem is that they run on different "clocks".

JavaScript only knows about individual pages,
not about ASP.NET user sessions.

The ASP.NET server knows about user sessions.

Juan T. Llibre
ASP.NET MVP
===========
"William F. Robertson, Jr." <th****@nameht.org> wrote in message
news:ud**************@tk2msftngp13.phx.gbl... ACaunter--
So in short, this is impossible to achieve completely.

Juan--
Ahhh. I had not thought about the new window, same session scenario.

What I suggested was to set his javascript redirection timeout the same as
the server. Unless of course asp.net ignores the SessionTimeout settings
and just randomly times out Sessions. In which case it wouldn't work.
The Application won't restart only
because a User Session expires/ends.


Ofcourse not, but the Application restart will cause all of the Sessions
to
be recreated on next postback. Thus they will be ended.

bill
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
re:
> If the user leaves a page up (open) for the 20 minute
> Session timeout, you can still direct them to another page.


Try it.

What you suggest will only enable Javascript redirection
after 20 minutes of inactivity in the page the JS script is in,
and is totally unrelated to the actual Session expiration/end.

What if the user has two windows open on your site,
and one of them is left open for the 20 minutes you
specify, but he is actively browsing the site in the other
window ( thereby keeping his Session alive ) ?

re:
> the only hole in the solution offered
> is the Application Restarts


The Application won't restart only
because a User Session expires/ends.


Juan T. Llibre
ASP.NET MVP
===========
"William F. Robertson, Jr." <th****@nameht.org> wrote in message
news:uz**************@TK2MSFTNGP10.phx.gbl...
>I disagree. If the user leaves a page up (open) for the 20 minute Session > timeout, you can still direct them to another page. If the user has left > your site, you wouldn't want to redirect them to the login page, nor
> can
> you.
>
> He was asking about redirecting a user automatically when their Session
> times out. Now the only hole in the solution offered is the
> Application
> Restarts, the session will be new, but there is no way to notifiy the
> browser.
>
> bill
>
> "Juan T. Llibre" <no***********@nowhere.com> wrote in message
> news:%2****************@TK2MSFTNGP09.phx.gbl...
>> Neither that, nor the other solutions offered, will work.
>>
>> When a session ends/expires, the server has no way
>> of knowing whether the user has already left the site
>> and is currently 10 sites away.
>>
>>
>>
>>
>> Juan T. Llibre
>> ASP.NET MVP
>> ===========
>> "Stefan Kiryazov" <ch***@bulgaria.com> wrote in message
>> news:11**********************@f14g2000cwb.googlegr oups.com...
>> > You can also put the following in Global.asax:
>> >
>> > protected void Session_End(Object sender, EventArgs e)
>> > {
>> > Response.Redirect( "login.aspx" );
>> > }



Nov 19 '05 #9
Thanks for the replies,
This javascript code, would I put this on each of my pages for my site???
<script language="javascript">
//this will call the javascript method _SessionExpired after 20 minutes

setTimeout( "_SessionExpired()", 20 * 60 * 1000 );

function _SessionExpired()
{
location.href = "login.aspx";
}
</script>


... and i don't have to worry about 2 windows being open and the one being
left for 20 mins, that won't happen on my site.. i hope :p.. but ya.. Right
now i have my timeout set for 1 hour i believe, so i was hoping that if the
session expires after the hour, the site will automatically go back to the
login page, knowing the session var's are gone, and they can restart them..

also, for the session expiring.. is it no matter what after an hour they are
gone, or only if the screen is left still, not used, for the hour...??

and whatabout this code, do i need to put it in my global page too??

protected void Session_End(Object sender, EventArgs e)
{
Response.Redirect( "login.aspx" );
}
thanks
Nov 19 '05 #10
re:
This javascript code, would I put this
on each of my pages for my site???
If all you want to do is insure that your users will always
have Session contents available, i.e., insure that their
sessions don't timeout when they leave their browsers
open on the same page, without doing anything alse for
a period of time which is larger that your Session Timeout
setting, all you'd need to do is use a Meta Refresh tag :
<meta http-equiv="refresh" content="600">

That would refresh the page every 10 minutes (600 seconds).
If you need a higher value, set the number to a larger value.

That is much simpler than the JavaScript solution,
which doesn't synchronize with Session timeout, anyway.

Be forewarned : users don't like applications/servers
messing with how they view the site, and this strategy
may well backfire on you, as would any other method
you use to insure that a page will refresh, or that a user
will be redirected against his will to other pages.

re: and whatabout this code,
do i need to put it in my global page too??
As previously said, setting protected void Session_End(Object sender, EventArgs e)
Response.Redirect( "login.aspx" );
will *not* work because when the session ends
the server has no way of sending a response to
the client, who might be long gone, anyway.


Juan T. Llibre
ASP.NET MVP
===========
"ACaunter" <Ad****@hotmail.com> wrote in message
news:54**********************************@microsof t.com... Thanks for the replies,
This javascript code, would I put this on each of my pages for my site???
<script language="javascript">
//this will call the javascript method _SessionExpired after 20 minutes

setTimeout( "_SessionExpired()", 20 * 60 * 1000 );

function _SessionExpired()
{
location.href = "login.aspx";
}
</script>


.. and i don't have to worry about 2 windows being open and the one being
left for 20 mins, that won't happen on my site.. i hope :p.. but ya..
Right
now i have my timeout set for 1 hour i believe, so i was hoping that if
the
session expires after the hour, the site will automatically go back to the
login page, knowing the session var's are gone, and they can restart
them..

also, for the session expiring.. is it no matter what after an hour they
are
gone, or only if the screen is left still, not used, for the hour...??

and whatabout this code, do i need to put it in my global page too??

protected void Session_End(Object sender, EventArgs e)
{
Response.Redirect( "login.aspx" );
}
thanks



Nov 19 '05 #11
Plus if I am typing in a long form and the 10 minutes hits, them whammo, my
last ten minutes worth of work are gone because the page will be
re-requested, and not posted.

Unless Juan instructs the meta tag will "post" a form rather than a "get".

Juan,

What if you set a httpHandler that did nothing and implement
IRequiresSessionState. Then use the javascript timer to change the url of a
hidden image on the page. It would hit the server and keep the session
alive.

bill

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uU**************@TK2MSFTNGP09.phx.gbl...
re:
This javascript code, would I put this
on each of my pages for my site???


If all you want to do is insure that your users will always
have Session contents available, i.e., insure that their
sessions don't timeout when they leave their browsers
open on the same page, without doing anything alse for
a period of time which is larger that your Session Timeout
setting, all you'd need to do is use a Meta Refresh tag :
<meta http-equiv="refresh" content="600">

That would refresh the page every 10 minutes (600 seconds).
If you need a higher value, set the number to a larger value.

That is much simpler than the JavaScript solution,
which doesn't synchronize with Session timeout, anyway.

Be forewarned : users don't like applications/servers
messing with how they view the site, and this strategy
may well backfire on you, as would any other method
you use to insure that a page will refresh, or that a user
will be redirected against his will to other pages.

re:
and whatabout this code,
do i need to put it in my global page too??


As previously said, setting
protected void Session_End(Object sender, EventArgs e)
Response.Redirect( "login.aspx" );


will *not* work because when the session ends
the server has no way of sending a response to
the client, who might be long gone, anyway.


Juan T. Llibre
ASP.NET MVP
===========
"ACaunter" <Ad****@hotmail.com> wrote in message
news:54**********************************@microsof t.com...
Thanks for the replies,
This javascript code, would I put this on each of my pages for my site???
<script language="javascript">
//this will call the javascript method _SessionExpired after 20 minutes

setTimeout( "_SessionExpired()", 20 * 60 * 1000 );

function _SessionExpired()
{
location.href = "login.aspx";
}
</script>


.. and i don't have to worry about 2 windows being open and the one being left for 20 mins, that won't happen on my site.. i hope :p.. but ya..
Right
now i have my timeout set for 1 hour i believe, so i was hoping that if
the
session expires after the hour, the site will automatically go back to the login page, knowing the session var's are gone, and they can restart
them..

also, for the session expiring.. is it no matter what after an hour they
are
gone, or only if the screen is left still, not used, for the hour...??

and whatabout this code, do i need to put it in my global page too??

protected void Session_End(Object sender, EventArgs e)
{
Response.Redirect( "login.aspx" );
}
thanks


Nov 19 '05 #12

William was on the right track with putting the redirect in th
global.asax, but it should be on session start, not end:
protected void Session_Start(Object sender, EventArgs e)
{
Response.Redirect( "login.aspx" );
}


A session-end will never reach the user/browser. But when that use
re-requests the page, a new session will start, and the session_star
event will fire, redirecting the user

--
NikkolBPosted from http://www.pcreview.co.uk/ newsgroup acces

Nov 19 '05 #13

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

Similar topics

1
by: Rayc | last post by:
I have a .NET login page that works fine locally but when I upload to my web host provider the login page keeps reappearing. When I click the login button, the login page reappears asking to login...
1
by: Wayne Smith | last post by:
Applies to: Microsoft FrontPage 2000, Microsoft Access 2000, IIS 5.0 Operating System: Microsoft Windows 2000 Professional I am trying to protect a portion of a web site by allowing users to...
1
by: Burak Kadirbeyoglu | last post by:
Dear ASP.NET Programmers, I am using forms authentication in my web application. I would like the users to be transferred to the login page when the session expires. I am using session state,...
4
by: The Eeediot | last post by:
Hello, folks! I am trying to design a login script / page for a set of administrative functions on my company's Intranet. I need something that is reasonably secure and I've been trying to rack...
1
by: leovega | last post by:
Hello, My aplication starts with a simple login window (login_page.aspx). Once the login/password is validated I redirect to an html which contains 3 frames. (mywebsite.html) The web site I...
5
by: guy | last post by:
I am not a web developer so this is probably easy! in a web app i have a login page if a user logs in, does stuff, logs out - which takes them back to the login page - how do i stop a new user...
6
by: divya | last post by:
I have a page name edit.asp which should expire immediately .The user cannot open this page directly he has to provide a password for entering this page.thus when the user enters edit.asp , it has...
5
by: simon | last post by:
well i have admin panel and agent panel. when i open admin panel and log in it works fine. but when agent opens agent panel in different pc and login and acts something like open a page or so,...
1
by: Kandiman | last post by:
Hiya, i made a asp page, and one of my divs (as a include) is as below. the problem is if the main page is resubmitted, i get logged out again?... heres the code.. i think its on the value=true...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.