我需要显示有多少用户正在浏览我的网站。该站点在iis7上运行,我们正在使用asp.net 3.5。
事件 session 的数量是否是一个好方法?
该数字不必非常准确。
不需要历史记录,我只想知道现在有多少用户“在线”,并将其显示在页面本身上。
最佳答案
您可以为此使用Windows Performance计数器(性能)
ASP.NET应用程序> session 事件计数器。
您可以使用System.Diagnostics命名空间访问这些性能计数器。
这段代码对我有用:
PerformanceCounter pc = new PerformanceCounter("ASP.NET Applications",
"Sessions Active", "__Total__", "MYSERVERHOSTNAME.domain");
while (true)
{
Console.WriteLine(pc.NextValue());
System.Threading.Thread.Sleep(1000);
}
我遇到了这个问题,因此如果计数器似乎过高,请在此处查看:http://support.microsoft.com/kb/969722
关于asp.net - 如何在任何给定时间找到站点(IIS7/asp.net)上的访问者/用户数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2719903/