Search This Blog

Tuesday, September 21, 2010

ASP.NET Push Redirect to a page on Session Timeout

 Usually we have some problem with the session timed out period and redirect the response to a page which will indicate user.

   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.

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) 
            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.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.