Link to home
Start Free TrialLog in
Avatar of sivachirravuri
sivachirravuriFlag for India

asked on

How to redirect to login page automatically, after session time out.

How to redirect to login page automatically, after session time out?
In my web application, user logs in in the application, after a certain time (30 mins) session times out and login page appears only AFTER user action.
I would like to redirect the user back to the login screen automatically (before user performs any action) after session has timed out.

Your suggestions will be greatly appreciated.
I used following code in pagerender of masterpage.
 
 HttpContext.Current.Response.AppendHeader("Refresh", Convert.ToString(((HttpContext.Current.Session.Timeout * 60) - 5)) + "; Url=homepage.aspx")
 
Also, i have Session_Start/Session_end in global.asax.

Open in new window

Avatar of naspinski
naspinski
Flag of United States of America image

There is no 'good' way to do this.  

One would be to simply include a META refresh tag set to the time you want to refresh (the 3600 is 3600 seconds/60 minutes):

<meta http-equiv="refresh" content="3600;url=http://yoursite/login.aspx"/>

Another way would be to call a Javascript or C#/VB timer and call the refresh when the timer hits a certain time.  With the C# option, you would check to make sure the session is dead.

If you included one of these methods on your page, it would be self-regulating since it would refresh every time the page refreshes which would correspond to the session refreshing.  
Avatar of sivachirravuri

ASKER

Thanks for you suggessions.
I have created a Javascript timer in class file & refreshing page. But i m getting JS error at the time of page refresh.
Can you suggest this appraoch with some sample code.
Keeping it as simple as possible:

<meta http-equiv="refresh" content="3600;url=http://yoursite/login.aspx"/>
Problem for using <meta http-equiv="refresh" content="3600;url=http://yoursite/login.aspx"/> is
I have almost 70-100 pages in my website. It will be hectic for me to include this in all pages.

Thanks, Sp
understandable, you could use this if you were using masterpages, are you?

If not I can throw together a js example.
ASKER CERTIFIED SOLUTION
Avatar of naspinski
naspinski
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, I use masterpages. But, can we give the following line master pages? I am not aware of that.
<meta http-equiv="refresh" content="3600;url=http://yoursite/login.aspx"/>
If yes, then my problem will be solved.

Alternative option:
This option I am trying to implement. I have global Pagebase.vb file that is called in all the forms. I will implement in that.
Javascript:
function timeout(){window.location = "http://google.com"}
call it in your html:
<body onload="setTimeout('timeout()', 5000)">

Regards,
If you place that in the <head> of your masterpage, it will be replicated on each page that uses the master.
Thanks for the quick replies. It solved my problem. Thanks a Ton.