You need to get the
Window.Closing Event[
^] which occurs directly after
Close [
^]is called, and can be handled to cancel window closure.
public event CancelEventHandler Closing
On this event you can check whether user is logged out or not, if not then cancel the window closure & prevent your window from closing.
Here is reference for
How to detect the browser close event in ASP.Net (C#)[
^] you may get some help from it.