Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Push Redirect on Session Timeout

Tags:

I'm looking for a tutorial, blog entry, or some help on the technique behind websites that automatically push users (ie without a postback) when the session expires. Any help is appreciated

like image 946
Michael Avatar asked Jan 27 '09 19:01

Michael


People also ask

How do you handle session timeout?

Use some jquery that keys off of your session timeout variable in the web. config. You can use this Jquery delay trick that when a specific time occurs (x number of minutes after load of the page), it pops up a div stating session timeout in x minutes. Nice, clean and pretty simple.


1 Answers

Usually, you set the session timeout, and you can additionally add a page header to automatically redirect the current page to a page where you clear the session right before the session timeout.

From http://aspalliance.com/1621_Implementing_a_Session_Timeout_Page_in_ASPNET.2

namespace SessionExpirePage {     public partial class Secure : System.Web.UI.MasterPage     {         public int SessionLengthMinutes         {             get { return Session.Timeout; }         }         public string SessionExpireDestinationUrl         {             get { return "/SessionExpired.aspx"; }         }         protected override void OnPreRender(EventArgs e)         {             base.OnPreRender(e);             this.PageHead.Controls.Add(new LiteralControl(                 String.Format("<meta http-equiv='refresh' content='{0};url={1}'>",                  SessionLengthMinutes*60, SessionExpireDestinationUrl)));         }     } } 

The SessionExpireDestinationUrl should link to a page where you clear the session and any other user data.

When the refresh header expires, it will automatically redirect them to that page.

like image 58
TJB Avatar answered Sep 28 '22 09:09

TJB