You can handle the event named 'onbeforeunload' of current window and within that event handler you can call the logout operation of the application.
Make an ajax call to the logout operation from the page methods and end the session on window closing of browser.
Please refer this link to get some idea how to start with :-
http://forums.asp.net/t/1969069.aspx?Call+c+method+inside+onbeforeunload+event+JS[
^]
Hope this is of help to you.