Clear the session when the user closes a browser window asp.net c#  

by ne on 2021-03-02 under Asp.net

use this code for clearing the session in asp.net on closing browser window:

<script type="text/javascript">
    function window.onbeforeunload()
    {
        var xmlHttp;
        try
        {
            // Firefox, Opera 8.0+, Safari
            xmlHttp=new XMLHttpRequest();
        }
        catch (e)
        {
            // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
        if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
        {
            xmlhttp.open("GET","exit.aspx",false);
            xmlhttp.send();
        }
     }
    </script>