asp.net visitors count (online users) for today-yesterday in .net 4
i wrote the below codes for visitors count (online users) for my application :
reference :
http://aspdotnetfaq.com/Faq/How-to-show-number-of-online-users-visitors-for-ASP-NET-website.aspxusing 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)
{
}
}
}
also i found the below link that uses IHttpModule :
http://blog.sb2.fr/post/2008/12/01/HowTo-Get-Current-Online-Users-Count-and-Infos-with-ASPNET.aspxi prefer to use simple global.asax for my purpose , but these two ways are too old (3 years earlier)
is there any better way in .net 4 for getting online users(visitors count) out there?also for getting some counts (such as yesterday) i need dat开发者_Python百科abase !
but is it ok to connect sql server 2008 in session_start or specially session_end in global asax ?thanks in advance
The "standard" approach I have seen is to use the Session_Start and Session_End within global.asax. ASP.net 4 has not changed this functionality. The only real limitation to this approach is that the server will still believe that the user is logged on until the session ends, which does not happen until the number of minutes has passed as specified in the session timeout configuration.
See this page for more information about session timeout: http://forums.asp.net/t/1283350.aspx
One more robust, and newer, but much more difficult approach, is to use polling to ensure that the client is always connected to the server. See this Wikipedia article for an overview of the subject: http://en.wikipedia.org/wiki/Comet_(programming))
精彩评论