0

I have created an MVC asp.net project I have to save date time while the browser is closed. I tried the solution given before. A sample project would help me to understand how it works?

2 Answers 2

0

This way i implement. Use onbeforeunload event when tab is closing.

<script type="text/javascript">
    window.onbeforeunload = function () {
        window.location.href = '/logout'; //your action to logout

    });
  };
</script>

or ajax call to logout

<script type="text/javascript">
    window.onbeforeunload = function () {
         $.ajax({
        type: "POST",
        url: "/logout",
        success: function (result) {
            //
        }
    });

    };
</script>
Sign up to request clarification or add additional context in comments.

4 Comments

I tried to call log out but the method is not invoked while closing the browser
I tried it to call ajax post and it worked @Hien Nguyen Thanks for the reply
while loading other page its logout how can i handle it?
if current url and new current url are different, it will be load new page, you can check it in your controller
0

Well you could add UserLastLoginDate or UserLastVistedDate in user table

Then the next time the userOpen the page you validate UserLastLoginDate with current Datetime, and there you have how much time the brwoser have been closed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.