Showing posts with label How To Add Session Timeout Popup in asp.net. Show all posts
Showing posts with label How To Add Session Timeout Popup in asp.net. Show all posts

Monday, June 23, 2014

How To Add Session Timeout Popup in asp.net

If you need to alert a user that his session will time out. This is how to do it. Add the following code snippet to the OnInit method on the base page of your application.
protected override void OnInit(EventArgs e)
   {
       base.OnInit(e);
       string script = "window.setTimeout(\"alert('Your session expired!');\", " + (Session.Timeout - 1) * 60000 + ")";
       this.Page.ClientScript.RegisterStartupScript(this.GetType(), "SessionManager", "<script language=\"javascript\">" + script + "</script>");

   }