Click here to Skip to main content
12,508,972 members (43,142 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
How to perform Auto Sign out on close of Browser in ASP.NET?
Posted 31-Jan-13 17:14pm
Updated 23-Feb-13 7:13am
ProgramFOX187.6K
v2
Comments
Raul Iloc 11-Apr-14 11:26am
   
Did you try my solution?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

In my main layout (master page) of my ASP.NET MVC site I am ussing the next java script:
<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.
  Permalink  
v3

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160927.1 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100