Click here to Skip to main content
15,886,792 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How to perform Auto Sign out on close of Browser in ASP.NET?
Posted
Updated 23-Feb-13 7:13am
v2
Comments
Raul Iloc 11-Apr-14 11:26am    
Did you try my solution?

1 solution

In my main layout (master page) of my ASP.NET MVC site I am ussing the next java script:
JavaScript
<script>
function onWindowClosing() { 
            if (window.event.clientX < 0 || window.event.clientY < 0)
            {
                $.ajax({
                    type: "POST",
                    url: "/Account/OnWindowClosing"
                });
            }
       };

       function onKeydown(evt){ 
            if (evt != undefined && evt.altKey && evt.keyCode==115) //Alt + F4 
            { 
                $.ajax({
                    type: "POST",
                    url: "/Account/OnWindowClosing"
                });
            } 
       };

       window.onbeforeunload = onWindowClosing; 
       window.document.onkeydown = onKeydown; 
 
    </script>

You should do something similar in your master page.
Then in your source code ("OnWindowClosing" action from "Account" controller in my example) you could do what you want.
 
Share this answer
 
v3

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