Deepak Veer

Deepak Veer

  • NA
  • 13
  • 7.8k

Limit only one session per user in ASP.NET mvc 4

Nov 29 2014 2:07 AM
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()">


    <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..."); }


                });
}


Answers (1)