统计网站访问量的问题

zq200487731 2008-06-03 02:09:45
//保存从文本中读取的信息
public static string strs;
//记录文本中访问时间
public static string day;
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
Application["counter"] = 0;
}

void Application_End(object sender, EventArgs e)
{
// 在应用程序关闭时运行的代码
int Stat = 0;
Stat = (int)Application["counter"];
//保存日期
string str = Stat.ToString();
// 将数据记录写入文件
string file_path = Server.MapPath("counter.txt");
StreamWriter srw = new StreamWriter(file_path, false);
srw.WriteLine(str);
srw.Close();
}

void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码

}

void Session_Start(object sender, EventArgs e)
{
Application.Lock();
int count;// 记录文本中的日访问量
// string NowDay; //记录文本中访问时间
StreamReader srd;
string file_path = Server.MapPath("~/counter.txt"); //取得文件的实际路径
srd = File.OpenText(file_path); //打开文件进行读取
while (srd.Peek() != -1)
{
strs = srd.ReadLine(); //保存从文件中读取的信息
}
srd.Close();
count = Convert.ToInt32(strs); //日访问量
object objcount = count;
//日访问量
Application["counter"] = objcount;

// 数据累加
int Stat = 0;
//获取Application对象中的日访问量
Stat = (int)Application["counter"];
Stat += 1;
object obj = Stat;
Application["counter"] = obj;
//保存日期
string str0 = obj.ToString();
// 将数据记录写入文件
//string file_path0 = Server.MapPath("counter.txt");
StreamWriter srw1 = new StreamWriter(file_path, false);
srw1.WriteLine(str0);
srw1.Close();
Application.UnLock();

}

void Session_End(object sender, EventArgs e)
{
// 在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
// 或 SQLServer,则不会引发该事件。
System.Web.Security.FormsAuthentication.SignOut();


} 这个是代码,有时候刷新页面后访问量会变成0,大家看看有什么问题
...全文
189 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ASPNETJAVA2011 2012-01-27
  • 打赏
  • 举报
回复
51yes,google有网站流量统计的功能服务...
Dennis_maomao 2008-06-04
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 zhouyongli41 的回复:]
我也想知道:用51yes,用google??什么意思
[/Quote]

51yes是专门做流量统计的网站,google同样也有 此功能。。

也许楼主是希望在自己的站点上显示 统计信息,,并不是为了统计而做统计。
zhouyongli41 2008-06-04
  • 打赏
  • 举报
回复
我也想知道:用51yes,用google??什么意思
niuniuhuang 2008-06-04
  • 打赏
  • 举报
回复
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
Application["counter"] = 0;
}
void Application_End(object sender, EventArgs e)
{
// 在应用程序关闭时运行的代码
int Stat = 0;
Stat = (int)Application["counter"];
//保存日期
string str = Stat.ToString();
// 将数据记录写入文件
string file_path = Server.MapPath("counter.txt");
StreamWriter srw = new StreamWriter(file_path, false);
srw.WriteLine(str);
srw.Close();
}
你这样服务一启动就会把它还原为0呀
zq200487731 2008-06-04
  • 打赏
  • 举报
回复
用51yes,用google??什么意思
mmcgzs 2008-06-03
  • 打赏
  • 举报
回复
用51yes,用google
海大富运动 2008-06-03
  • 打赏
  • 举报
回复
mark,学习啊!这个是我需要的 ,达人来帮忙解答了
s208ping 2008-06-03
  • 打赏
  • 举报
回复
别用 Application啊
MasDn 2008-06-03
  • 打赏
  • 举报
回复
用Yahoo统计
zq200487731 2008-06-03
  • 打赏
  • 举报
回复
大人 大人
zq200487731 2008-06-03
  • 打赏
  • 举报
回复
大家来帮我看看啊

62,248

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧