asp.net访客数量(在线用户)今天 – 昨天在.net 4

我为我的应用程序编写了以下访问者数量(在线用户)代码:

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

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Security; using System.Web.SessionState; using CardCharge.Classes; namespace CardCharge { public class Global : System.Web.HttpApplication { protected void Application_Start(object sender, EventArgs e) { Application["OnlineUsers"] = 0; } protected void Session_Start(object sender, EventArgs e) { Application.Lock(); Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1; Application.UnLock(); } protected void Application_BeginRequest(object sender, EventArgs e) { } protected void Application_AuthenticateRequest(object sender, EventArgs e) { } protected void Application_Error(object sender, EventArgs e) { } protected void Session_End(object sender, EventArgs e) { Application.Lock(); Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1; Application.UnLock(); } protected void Application_End(object sender, EventArgs e) { } } } 

我也找到了使用IHttpModule的以下链接:
http://blog.sb2.fr/post/2008/12/01/HowTo-Get-Current-Online-Users-Count-and-Infos-with-ASPNET.aspx

我更喜欢使用简单的global.asax作为我的目的,但这两种方式太旧了(3年前)
是否有更好的方式在.net 4中获取在线用户(访客数量)?

也为了得到一些计数(如昨天)我需要数据库!
但是可以在session_start中连接sql server 2008,还是在全局asax中连接session_end?

提前致谢

我看到的“标准”方法是在global.asax中使用Session_Start和Session_End。 ASP.net 4尚未更改此function。 此方法的唯一真正限制是服务器仍然会认为用户已登录,直到会话结束,直到会话超时配置中指定的分钟数已过去为止。

有关会话超时的详细信息,请参阅此页面: http : //forums.asp.net/t/1283350.aspx

一种更强大,更新但更困难的方法是使用轮询来确保客户端始终连接到服务器。 有关该主题的概述,请参阅此维基百科文章: http : //en.wikipedia.org/wiki/Comet_ (programming ))