Click here to Skip to main content
15,999,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on one web application in which i want to make sure that website allow only one login per user at a time.
when user login i am updating table column islogged=1 when logoff i am updating islogged =0
but the problem is when user session timeout or if user closing browser i am unable to capture this events.i am using sqlserver state to store sessions so Session_End event is not fired in this state .
it only works in InProc State. and also in browser close event i have tried onunload event. but this event is fired on tab closed also. not able to differentiate tab close and browser close.
i want only one concurrent user login. is there any other way to achieve this.

i am using this code to capture browser close event.
<body class="fixed-top" onclick="clicked=true;" onunload="CheckBrowser()">

JavaScript
   <script type="text/javascript">
        var clicked = false;
       // var xmlHttp
    //    var browser = navigator.appName;

        function CheckBrowser() {
            debugger

            //  var browserClose = isUserClickedCloseButton();
            if (clicked == false) {
                $.ajax({
                    url: "@Url.Content("~/Account/LogOff")",
                    type: 'Post',
                    success: function (data) {

                    },
                    error: function () { alert("Error On Logut..."); }

                });
}
Posted
Updated 18-May-18 19:16pm
v2

 
Share this answer
 
<script type="text/javascript"> 
    var clicked = false;
    function CheckBrowser()
    {
        debugger;
        if (clicked == false)
        {
            //Browser closed
        }
        else
        {
            //redirected 
            clicked = false;
        }
    }
 
    function bodyUnload()
    {
        debugger;
        if (clicked == false)//browser is closed
        {
            debugger;
            var request = GetRequest();
           
            request.open("GET", "Logout", true);
            request.send();
        }
    }
 
    function GetRequest()
    {
        debugger;
        var request = null;
        if (window.XMLHttpRequest)
        {
            //incase of IE7,FF, Opera and Safari browser
            request = new XMLHttpRequest();
        }
        else
        {
            //for old browser like IE 6.x and IE 5.x
            request = new ActiveXObject('MSXML2.XMLHTTP.3.0');
        }
        return request;
    }



and add this in body tag
onunload="bodyUnload();" Onclick="clicked=true;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900