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)
       string script = "window.setTimeout(\"alert('Your session expired!');\", " + (Session.Timeout - 1) * 60000 + ")";
       this.Page.ClientScript.RegisterStartupScript(this.GetType(), "SessionManager", "<script language=\"javascript\">" + script + "</script>");

Post a Comment

Please do not post any spam link in the comment box😊

Previous Post Next Post

Blog ads