Sunday, July 31, 2011

Clear the session when the user closes a window in ASP .NET

You can write you code of Clearing the Session in the exit.aspx page and you have to request the page when user closes the window. This will clear the session.
<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>
Post a Comment

Find a cool free stuff everyday

Giveaway of the Day

Hiren Bharadwa's Posts

DotNetJalps