我该如何制作可以计算访客人数的柜台 [英] how can i make the counter which count the number of visitors
本文介绍了我该如何制作可以计算访客人数的柜台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何创建一个计数器来统计访问者的数量?
How can I make a counter which counts the number of visitors?
推荐答案
您可以使用应用程序级变量并利用Global.asax中的事件
步骤:
1.声明变量
Hi,
u can use Application level variables and make use of the events in Global.asax
Steps:
1. Declare Variables
private static int totalNumberOfUsers = 0;
private static int currentNumberOfUsers = 0;
2.添加属性
2. Add Properties
public static int TotalNumberOfUsers
{
get
{
return totalNumberOfUsers;
}
}
public static int CurrentNumberOfUsers
{
get
{
return currentNumberOfUsers;
}
}
3.会话开始事件
3. Session Start Event
protected void Session_Start(Object sender, EventArgs e)
{
totalNumberOfUsers += 1;
currentNumberOfUsers += 1;
}
4.会话结束事件
4.Session End Event
protected void Session_End(Object sender, EventArgs e)
{
currentNumberOfUsers -= 1;
}
5.从其他页面访问变量
5.Access variables from other page
int currentNumberOfUsers = HitCounters.Global.CurrentNumberOfUsers;
int totalNumberOfUsers = HitCounters.Global.TotalNumberOfUsers;
请参考 http://imar.spaanjaars .com/223/howto-create-a-hit-counter-using-the-globalasax-file-in-aspnet-1x [ ^ ]
:thumbsup:还原以得到进一步的澄清
Refer http://imar.spaanjaars.com/223/howto-create-a-hit-counter-using-the-globalasax-file-in-aspnet-1x[^]
:thumbsup: Revert for further clarification
对于Web应用程序,请尝试:
在与整个应用程序交互的 Global.asax 文件中编写代码.
示例代码如下:
For web application, try:
Write code in Global.asax file which interacts with the entire application.
The sample code is given below:
void Application_OnStart(Object Sender, EventArgs E)
{
Application["CurrentUsers"] = 0;
}
void Session_OnStart(object Sender, EventArgs E)
{
Application.Lock();
Application["CurrentUsers"] = System.Convert.ToInt32(Application["CurrentUsers"]) + 1;
Application.UnLock();
}
void Session_OnEnd(object Sender, EventArgs E)
{
Application.Lock();
Application["CurrentUsers"] = System.Convert.ToInt32(Application["CurrentUsers"]) - 1;
Application.UnLock();
}
浏览以下链接..,这可能对您有帮助
http://www.15seconds.com/issue/021119.ht [
Go through the below link .., this may help you
http://www.15seconds.com/issue/021119.ht[^]
这篇关于我该如何制作可以计算访客人数的柜台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文