I made a simple web app using asp.net C# and I made a code to logout automatically from the website and redirect the user to the login page when the session expire, but I have a problem which is the website logout and redirect the user to the login page even if the user is active and clicking on buttons and moving the mouse and in this case I want the session to be alive and make it expire when the user don't do anything during the timeout period just like most of the websites.
Here is my code to end session:
web.config:
<sessionState timeout="1"></sessionState>
main_page.aspx:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
AutoRedirect();
}
public void AutoRedirect()
{
int int_MilliSecondsTimeOut = (this.Session.Timeout * 6000);
string str_Script = @"
<script type='text/javascript'>
intervalset = window.setInterval('Redirect()'," +
int_MilliSecondsTimeOut.ToString() + @");
function Redirect()
{
window.location.href='/login.aspx';
}
</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Redirect", str_Script);
}