Session_End 可以在窗口关闭时触发吗? (ASP.NET)

发布于 2024-12-12 20:02:33 字数 907 浏览 1 评论 0原文

我在网站上放置了一个“在线”计数器,并且遇到了这两个相互矛盾的来源。

这个(我正在使用这个示例代码):

http://aspdotnetfaq.com/Faq/How-to-show-number-of-online-users-visitors-for-ASP-NET-website.aspx

...说的是:

此外,当用户关闭浏览器或未单击中的任何链接时 我们的网站、会话过期以及我们的“OnlineUsers”全局变量 减少了。

然而,这个:

http://www.velocityreviews.com/forums/ t383710-session-end-guarantee.html

...说:

关闭浏览器窗口或浏览其他站点不会导致 Session_End 至少不会立即触发 - 服务器已 绝对无法知道客户端计算机上发生了什么,直到 它从中获取另一个 HttpRequest。在本例中,Session_End 当会话自然超时时将触发。

我已经测试过,似乎 Session_End 不会触发。

我基本上希望你们对此进行确认或评论。

是否可以在浏览器关闭时更新在线计数器?

I am putting an "online" counter on a website, and I have run into these two contradicting sources.

This one (I am using this example code):

http://aspdotnetfaq.com/Faq/How-to-show-number-of-online-users-visitors-for-ASP-NET-website.aspx

...says that:

Also when user closes his browser or does not click on any links in
our website, session expires, and our "OnlineUsers" global variable
is decreased.

However, this one:

http://www.velocityreviews.com/forums/t383710-session-end-guarantee.html

...says that:

Closing the browser window, or browsing to another site will NOT cause
Session_End to fire, at least, not straightaway - the server has
absolutely no way of knowing what happens on the client machine until
it gets another HttpRequest from it. In this instance, Session_End
will fire when the session times out naturally.

I have tested and it seems that Session_End DOES NOT fire.

I basically want you guys to confirm or comment on this.

Is it possible to update the online counter on browser-close?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

驱逐舰岛风号 2024-12-19 20:02:33

第二个是真的

关闭浏览器窗口或浏览其他站点不会导致
Session_End 至少不会立即触发 - 服务器已
绝对无法知道客户端计算机上发生了什么,直到
它从中获取另一个 HttpRequest。在本例中,Session_End
当会话自然超时时将触发。

默认情况下,会话超时为 20 分钟。您可以通过 20 分钟不在您的网站上进行任何活动来确认这一点。

The second is true

Closing the browser window, or browsing to another site will NOT cause
Session_End to fire, at least, not straightaway - the server has
absolutely no way of knowing what happens on the client machine until
it gets another HttpRequest from it. In this instance, Session_End
will fire when the session times out naturally.

Session time out is 20 minutes by default. You can confirm this by not doing any activity on your website for 20 min.

小嗲 2024-12-19 20:02:33

你的两个链接并不矛盾。第一个链接的措辞很糟糕,但它基本上说明了第二个链接的内容。如果这样写就更容易理解了:

此外,当用户关闭浏览器或未单击我们网站中的任何链接(一段时间后)时,会话将过期,并且我们的“OnlineUsers”全局变量会减少。

另请注意,Session_End 可能并不总是触发,特别是在会话被终止或退回时(例如,如果您更新 web.config、工作进程回收,或者在某些情况下发生未捕获的异常)。

Your two links are not contradictory. The first link is poorly worded, but it basically says what the second link says. It would be easier to understand if it were written like this:

Also when user closes his browser or does not click on any links in our website (after a period of time) the session will expire, and our "OnlineUsers" global variable is decreased.

Also note that Session_End may not always fire, especially if the session is killed or bounced (for example, if you update the web.config, the worker process recycles, or in some cases an uncaught exception occurs).

靖瑶 2024-12-19 20:02:33

正如稍后在发布的第一个链接中指出的,Session_End 事件在会话超时到期后触发。如果与会话关联的用户在会话超时值到期之前未向服务器发送请求,则将触发 session_end 事件,并且会话将从内存中删除。

用于 asp.net 会话状态的 MSDN: http://msdn.microsoft.com/en -us/library/ms178581.aspx

As is pointed out later in the first link posted the Session_End event fires after the session timeout expires. If the user who is associated with a session sends no requests to the server before the session timeout value expires the session_end event will be fired and the session will be removed from memory.

MSDN for asp.net session state: http://msdn.microsoft.com/en-us/library/ms178581.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文