利用 ASP.NET 的Timer 来实现的访问统计,感觉比较适合高访问量的网站
2007-04-21 01:49
666 查看
首先是因为晚上我要把我的博客的访问统计加上去的.起初的想法很简单 随便在 Session_Start 里面,自动往数据表里加 1
但考虑到如果访问人数很高的话是不是每次都很频烦的访问(还好我的访问量并不高
).
后来想到在Application_Start的时候存数据到 缓存里,Application_End 存进数据表不就得了,.貌似这个想法不错.但有一个问题,就是不可预测的因素,什么服务突然怎么怎么样啦.所以现在我的做法是,把数据 保存在 缓存里 然后利用timer间隔一定时间往数据表里写.
static Timer timer=new Timer(100 * 60*30);
void Application_Start(object sender, EventArgs e)
{
/---省略---/
string dtc = "1";
if (dr.Read())
{
dtc = dr["vr_count"].ToString();
}
dr.Close();
Application["total"] = dtc;
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Interval = 100 * 60 * 30;
timer.Enabled = true;
}
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
int total = Application["total"] != null ? Convert.ToInt32(Application["total"].ToString()) : 0;
if (total != 0)
{
/--数据更新--/
}
}
void Session_Start(object sender, EventArgs e)
{
if (Application["total"] == null)
{
int total=1;
Application.Lock();
Application["total"] = total;
Application.UnLock();
}
else
{
int total = Application["total"] != null ? Convert.ToInt32(Application["total"].ToString()) : 0;
Application.Lock();
total++;
Application["total"] = total;
Application.UnLock();
}
}
很简单,,但效果已经达到了,,不知道这样做有没有什么不足,,望指教...
http://dubox.cn/content-44.aspx
但考虑到如果访问人数很高的话是不是每次都很频烦的访问(还好我的访问量并不高
).
后来想到在Application_Start的时候存数据到 缓存里,Application_End 存进数据表不就得了,.貌似这个想法不错.但有一个问题,就是不可预测的因素,什么服务突然怎么怎么样啦.所以现在我的做法是,把数据 保存在 缓存里 然后利用timer间隔一定时间往数据表里写.
static Timer timer=new Timer(100 * 60*30);
void Application_Start(object sender, EventArgs e)
{
/---省略---/
string dtc = "1";
if (dr.Read())
{
dtc = dr["vr_count"].ToString();
}
dr.Close();
Application["total"] = dtc;
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Interval = 100 * 60 * 30;
timer.Enabled = true;
}
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
int total = Application["total"] != null ? Convert.ToInt32(Application["total"].ToString()) : 0;
if (total != 0)
{
/--数据更新--/
}
}
void Session_Start(object sender, EventArgs e)
{
if (Application["total"] == null)
{
int total=1;
Application.Lock();
Application["total"] = total;
Application.UnLock();
}
else
{
int total = Application["total"] != null ? Convert.ToInt32(Application["total"].ToString()) : 0;
Application.Lock();
total++;
Application["total"] = total;
Application.UnLock();
}
}
很简单,,但效果已经达到了,,不知道这样做有没有什么不足,,望指教...
http://dubox.cn/content-44.aspx
相关文章推荐
- 怎样在Asp.net中实现当前网站的访问用户数量统计
- ASP.net中实现网站访问量统计的方法
- ASP.NET中利用Application和Session统计在线人数、历史访问量
- Asp.net cookie实现记录网站访问次数
- 关于云服务器的ASP.Net MVC网站实现被外网访问
- 关于云服务器的ASP.Net MVC网站实现被外网访问
- asp 实现同一帐号,防止多人同时登录、获取在线列表、实现登录日志(可用户统计在线时长),适合用户访问量大的系统
- 关于云服务器的ASP.Net MVC网站实现被外网访问
- 关于云服务器的ASP.Net MVC网站实现被外网访问
- asp.net 利用微软数据访问类库结合AjaxPro实现无刷新下拉框级联
- 如何利用缓存提高asp.net网站访问速度
- asp.net 访问页面访问统计实现 for iis7
- asp.net 访问页面访问统计实现
- 关于云服务器的ASP.Net MVC网站实现被外网访问
- 关于云服务器的ASP.Net MVC网站实现被外网访问
- 网站今日访问,总访问及在线人数统计 asp.net
- ASP.NET中实现简单访问统计计数器
- ASP.NET MVC中利用AuthorizeAttribute实现访问身份是否合法以及Cookie过期问题的处理
- 关于云服务器的ASP.Net MVC网站实现被外网访问
- 关于云服务器的ASP.Net MVC网站实现被外网访问