Logoff User when browser tab page is closed, ASP.NET MVC

后端 未结 5 419
攒了一身酷
攒了一身酷 2021-02-06 02:29

In one of the ASP.NET MVC apps we would like to logoff the user automatically if he closes the browser tab in which the app is opened.

We are using the following code wh

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-06 03:02

    I have not tried this myself, but I think the following approach should work:

    On the client side, you can use the OnUnload event of your document to launch a javascript function that would call your server-side signout method via ajax.

    On the server side, you should have the action method call FormsAuthentication.SignOut() and Session.Abandon();

提交回复
热议问题