简体   繁体   English

计算Web应用程序的在线用户数

[英]counting online number of users of a web application

I am using ASP.Net + .Net 3.5 + VS2008 + IIS 7.0 + C# to develop a web application. 我正在使用ASP.Net + .Net 3.5 + VS2008 + IIS 7.0 + C#来开发Web应用程序。 I want to count how many users are online. 我想算一下有多少用户在线。 This is my current implementation, 这是我目前的实施,

  1. when Session_Start is called, I will increase # of users online by 1; 调用Session_Start时,我会将在线用户数增加1;
  2. when Session_End is called, I will decrease # of users online by 1. 当调用Session_End时,我会将在线用户数减少1。

Two questions, 两个问题,

A Is that implementation correct? A该实施是否正确?

B. Another question is, I think this method can not track # of users of real time, since when user closes the browser, Session_End will not be called immediately (Session_End will be deferred to be called). B.另一个问题是,我认为这种方法无法实时跟踪用户数,因为当用户关闭浏览器时,Session_End不会立即被调用(Session_End将被推迟调用)。 Correct? 正确?

Are you using ASP.NET membership? 您使用的是ASP.NET会员资格吗?

Membership.GetNumberOfUsersOnline()

You can customise the amount of time a user is considered to be "online" in web.config - eg 您可以自定义用户在web.config被视为“在线”的时间 - 例如

<membership defaultProvider="..." 
            userIsOnlineTimeWindow="10" 
  <providers>
    ....
  </providers>
</membership>

Read more here 在这里阅读更多

Another problem with using Session_End is that it does not fire reliably, in fact if you use anything but inproc session state you cannot rely on this at all. 使用Session_End的另一个问题是它不能可靠地触发,事实上如果你使用除了inproc会话状态之外的任何东西你完全不能依赖它。

A better option is to use the the Membership provider, take a look at Membership.GetNumberOfUsersOnline() 更好的选择是使用Membership提供者,看看Membership.GetNumberOfUsersOnline()

Your implementation won't be very accurate - if a user logs on using two browsers your counter will increase by two. 您的实施将不会非常准确 - 如果用户使用两个浏览器登录,您的计数器将增加两个。

A lot of sites just record logons and then do a count of the number of unique logons in the last x minutes to get an online total. 许多网站只记录登录,然后计算最近x分钟内唯一登录的数量,以获得在线总数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM