Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-05-14
9
Medium Priority
?
1,400 Views
Last Modified: 2013-11-07
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

0
Comment
Question by:sivachirravuri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 21

Expert Comment

by:naspinski
ID: 21562033
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.  
0
 
LVL 5

Author Comment

by:sivachirravuri
ID: 21562788
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.
0
 
LVL 21

Expert Comment

by:naspinski
ID: 21562820
Keeping it as simple as possible:

<meta http-equiv="refresh" content="3600;url=http://yoursite/login.aspx"/>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:sivachirravuri
ID: 21563340
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
0
 
LVL 21

Expert Comment

by:naspinski
ID: 21563376
understandable, you could use this if you were using masterpages, are you?

If not I can throw together a js example.
0
 
LVL 21

Accepted Solution

by:
naspinski earned 1200 total points
ID: 21563505
Javascript:
function timeout(){window.location = "http://google.com"}

call it in your html:
<body onload="setTimeout('timeout()', 5000)">

But you would still have to put this into every page... not sure how you are going to accomplish this without masterpages.
0
 
LVL 5

Author Comment

by:sivachirravuri
ID: 21564116
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,
0
 
LVL 21

Expert Comment

by:naspinski
ID: 21564564
If you place that in the <head> of your masterpage, it will be replicated on each page that uses the master.
0
 
LVL 5

Author Closing Comment

by:sivachirravuri
ID: 31457750
Thanks for the quick replies. It solved my problem. Thanks a Ton.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question