如何计算asp.net C#中网站的访问者数量 [英] how to count number of visitors for website in asp.net c#

查看:42
本文介绍了如何计算asp.net C#中网站的访问者数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算asp.net c#中网站的访问者数量?

How do I count the number of visitors for website in asp.net c#?

我正在使用以下代码:

在global.asax页面中:

In global.asax page:

<%@ Application Language="C#" %>

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup
    Application["NoOfVisitors"] = 0;
}

void Session_Start(object sender, EventArgs e)
{
    // Code that runs when a new session is started
    Application.Lock();
    Application["NoOfVisitors"] = (int)Application["NoOfVisitors"] + 1;
    Application.UnLock();
}

在.aspx页中:

<asp:Label runat="server" ID="lbluser" />

在.aspx.cs中:

In .aspx.cs:

protected void Page_Load(object sender, EventArgs e)
{
    lbluser.Text = Application["NoOfVisitors"].ToString();
}

应用程序计数器每隔一小时重置为0 ... 我在哪里统计用户数量有误?

The application counter is resetting to 0 every one hour ... Where have I erred in counting the number of users?

推荐答案

如果您的应用程序托管在IIS中并且具有应用程序池,则可以检查应用程序池回收设置.根据您的版本,默认值为1740或29小时.也许您的应用程序池配置为60或大约那个值?下一个要检查的设置是空闲超时.我相信它在新服务器上的默认值为20.您可以将其设置为0.建议您在更改这些设置之前先阅读这些设置.

If your application is hosted in IIS and has an application pool, you can check the Application Pool Recycling Settings. Depending on your version, the default is 1740 or 29 hours. Maybe the pool for your application is configured to 60 or around that value? The next setting to check is the Idle Time Out. I believe its default value is 20 on a new server. You can set this to 0. I recommend you read about these settings prior to changing them.

这篇关于如何计算asp.net C#中网站的访问者数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆