0

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()">

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

                });
}
deepak neo
  • 61
  • 1
  • 8

2 Answers2

0

alternatively you can store store session id in DB along with the current loggedin status as true or false. when user hits just check if loggedin flag is true and take the action needed

Akshay Randive
  • 384
  • 2
  • 10
  • i am storing user logged in and out status in database.but what when user close the browser or session timeout. in this cases i need update status as logout in database. how to capture session timeout event in sqlstate mode.? – deepak neo Nov 29 '14 at 09:03
  • If you are using SqlState server mode then it deletes the expired sessions by itself you wont find an event for this but when user tries other action say navigating to other page you can check if particular session exists im sql [this may help you](http://stackoverflow.com/questions/8723504/delete-session-from-database-after-it-expired) – Akshay Randive Nov 29 '14 at 09:11
0

Please check the below links which has similar Q&A.

Only one concurrent login per user in Asp.net

Only one concurrent login per UserID in Asp.net

Community
  • 1
  • 1
Habib Sheikh
  • 139
  • 1
  • 5