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)
{
$.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.