且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

计数使用asp.net在线用户

更新时间:2023-12-02 13:16:52

您可以使用 onUserExit jQuery插件调用一些服务器端的code和放弃会话。激活onUserExit的文件准备:

You could use onUserExit jQuery plugin to call some server side code and abandon the session. Activate onUserExit on document ready :

<script type="text/javascript">
  jQuery(document).ready(function () {

    jQuery().onUserExit({
      execute: function () {
        jQuery.ajax({
          url: '/EndSession.ashx', async: false
        });
      },
      internalURLs: 'www.yourdomain.com|yourdomain.com'
    });
  });
</script>

和在EndSession.ashx放弃会话和服务器端Session_End中会被叫做:

And in EndSession.ashx abandon the session and server side Session_End will be called :

public void ProcessRequest(HttpContext context)
{
  context.Session.Abandon();
  context.Response.ContentType = "text/plain";
  context.Response.Write("My session abandoned !");
}

请注意,这不会涵盖所有情况下(例如,如果用户浏览器死于槽任务管理器)。

note that this will not cover all cases (for example if user kills browser trough task manager).