在asp.net中网站的总访问量怎么做啊 谢谢哈 要具体代码与过程哦 !

[复制链接]
查看11 | 回复2 | 2011-5-27 12:24:54 | 显示全部楼层 |阅读模式
回复

使用道具 举报

千问 | 2011-5-27 12:24:54 | 显示全部楼层
Global.asax文件统计网站的总访问量
voidApplication_Start(objectsender,EventArgse)
{
//在应用程序启动时运行的代码
intcount=0;
StreamReadersrd;
//取得文件的实际路径
stringfile_path=Server.MapPath(\"counter.txt\");
//打开文件进行读取
srd=File.OpenText(file_path);
while(srd.Peek()!=-1)
{
stringstr=srd.ReadLine();
count=int.Parse(str);

}
srd.Close();
objectobj=count;
//将从文件中读取的网站访问量存放在Application对象中
Application[\"counter\"]=obj;

}

voidApplication_End(objectsender,EventArgse)
{
//在应用程序关闭时运行的代码
intStat=0;
Stat=(int)Application[\"counter\"];
stringfile_path=Server.MapPath(\"counter.txt\");
StreamWritersrw=newStreamWriter(file_path,false);
srw.WriteLine(Stat);
srw.Close();

}

voidApplication_Error(objectsender,EventArgse)
{
//在出现未处理的错误时运行的代码

}

voidSession_Start(objectsender,EventArgse)
{
//在新会话启动时运行的代码
Application.Lock();
//数据累加
intStat=0;
//获取Application对象中保存的网站总访问量
Stat=(int)Application[\"counter\"];
Stat=1;
objectobj=Stat;
Application[\"counter\"]=obj;
//将数据记录写入文件
stringfile_path=Server.MapPath(\"counter.txt\");
StreamWritersrw=newStreamWriter(file_path,false);
srw.WriteLine(Stat);
srw.Close();
Application.UnLock();

}

voidSession_End(objectsender,EventArgse)
{
//在会话结束时运行的代码。
//注意:只有在Web.config文件中的sessionstate模式设置为
//InProc时,才会引发Session_End事件。如果会话模式设置为StateServer
//或SQLServer,则不会引发该事件。

}









<h4class=\"ask\">追问


那后台不需要添加代码了嘛?!
回复

使用道具 举报

千问 | 2011-5-27 12:24:54 | 显示全部楼层
在你调用访问量的地方读出Application[\"counter\"]的数,显示即可。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行