Wednesday, 12 August 2015

Avoid Prevent Session TimeOut In Asp.Net To Keep Session Alive

We can Write a JavaScript to call a blank or empty page on the server at regular interval .

I have created a sessionalive.aspx page and will call it every 10 minutes through JavaScript to slide the expiration.

<script type="text/javascript">
    function ResetTimeOut() {
        var requestParms = new Sys.Net.WebRequest();
        requestParms.set_url("sessionalive.aspx");
        requestParms.set_httpVerb("POST");
        var message = "hi";
        requestParms.set_body(message);
        requestParms.get_headers()["Content-Length"] = message.length;
        requestParms.add_completed(DoNothing);
        requestParms.invoke();
    }

    function DoNothing(executor,eventArgs) {
    }
    window.setInterval("ResetTimeOut();",600000);
</script>