Pseudo code:
- Read the timeout setting in codebehind
- Register a ClientScriptblock (
setTimeout
passing the timeout period (20 * 60))
- On timeout, display a warning label on the page
Sample code:
public void RegisterTimeoutWarning(System.Web.UI.Page Page)
{
var timeout = HttpContext.Current.Session.Timeout * 60 * 1000;
Page.ClientScript.RegisterStartupScript(Page.GetType(),
"timeoutWarning",
string.Format("setTimeout(function () {{ alert('Session about to expire'); }}, {0});", timeout), true);
}
Of course, you can improve the client side display (rather than showing an alert) by displaying warning popups or even a confirm popup which you can then use to renew the session.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…