Tuesday, December 28, 2010

How to inform the user that the session is going to end in next few minutes due to inactivity.

Write code in masterpage.
protected override void OnInit(EventArgs e)
{
if (!(Request.Url.ToString().IndexOf("Login.aspx") > 0) && InternalSession.InternalUserInformation!=null)
{
base.OnInit(e);
string script = "window.setTimeout(\"SessionEnd('" + ResolveClientUrl("~/Logout.aspx") + "');\"," + (Session.Timeout - 1) * 60000 + ");";
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "SessionTimeout", script, true);
}
}


Js file.
In the Javascript file put the below code.
function SessionEnd(url) {
alert('**ATTENTION** There has been no activity for the last 15 minutes Your session will expire in 5 minutes. If you perform no action before it expires, you will be required to log in again');
}

No comments:

Post a Comment