Session_End 可以在窗口关闭时触发吗? (ASP.NET)
我在网站上放置了一个“在线”计数器,并且遇到了这两个相互矛盾的来源。
这个(我正在使用这个示例代码):
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第二个是真的
默认情况下,会话超时为 20 分钟。您可以通过 20 分钟不在您的网站上进行任何活动来确认这一点。
The second is true
Session time out is 20 minutes by default. You can confirm this by not doing any activity on your website for 20 min.
你的两个链接并不矛盾。第一个链接的措辞很糟糕,但它基本上说明了第二个链接的内容。如果这样写就更容易理解了:
另请注意,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 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).
正如稍后在发布的第一个链接中指出的,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