void Application(object sender ,EventArgs)
{
Application["counter"]=0;
Application["day"]=DateTime.Now.ToString();
}
void Seesion_Start(object sender,EventArgs e)
{
Application.Lock();
int count;//记录文本中的访问量
System.IO.StreamReader srd;
string NowDay;//记录文本中访问时间
string file_path=Server.MapPath("count.txt");
srd=System.IO.File.OpenText(file_path);
while(srd.Peek()!=-1)
{
string str=srd.ReadLine();//保存从文件中读取的信息
}
srd.Close();
string str[]=str.Split(',');//将读取的信息放在字符窜数组中
count Convert.ToInt32(str[0]);//日访问量
string day=str[1];//最后一次访问时间
NowDay=DateTime.Now.ToString();
//文件中保存的时间值也系统时间相比,如果系统时间大,则重新开始计数
if(DateTime.Compare(Convert.ToDateTime(NowDay),COnvert.ToDateTime(day))>=0)
{<

这是一个使用C#实现的统计网站日访问量的代码片段。通过读取和更新`count.txt`文件来记录每天的访问次数。当系统时间大于文件中记录的最后访问时间时,会清零并开始新的计数。同时,应用使用Application对象进行数据存储和同步。
最低0.47元/天 解锁文章
865

被折叠的 条评论
为什么被折叠?



