zoukankan      html  css  js  c++  java
  • 创建站点计数器

    一般每个站点都有一个计数器,以帮助站长来了解站点的访问量。要实现这一功能有很多的方法。下面我就提供一个.net技术下的站点计数器的实现方法。

       首先在global.asax文件中加入以下代码 :
            void Application_Start(object sender, EventArgs e)
        {
           System.IO.StreamReader rd = new System.IO.StreamReader(Server.MapPath("Counter.txt"));
            int count=int.Parse(rd.ReadLine());
            Application.Lock();
            Application["Count"]=count;       
            Application.UnLock();
            rd.Close();
        }
       
        void Application_End(object sender, EventArgs e)
        {
           System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("Counter.txt"));
            sw.WriteLine(Application["Count"]);
            sw.Close();
        }
          
        void Session_Start(object sender, EventArgs e)
        {
            Application.Lock();
            Application["Count"] = Convert.ToInt16(Application["Count"]) + 1;
            Application.UnLock();
            System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("Counter.txt"));
            sw.WriteLine(Application["Count"]);
            sw.Close();
         
        }

        void Session_End(object sender, EventArgs e)
        { 
            System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("Counter.txt"));
            sw.WriteLine(Application["Count"]);
            sw.Close();      
        }

             然后便可以在网页中要显示计数器的地方用Appliation["Count"]对象来显示了。
    是不是很简单呢?

  • 相关阅读:
    在线添加磁盘,扩展LVM卷案例
    iOS 通过代码关闭应用程序
    hdu1443(约瑟夫环游戏的原理 用链表过的)
    Mapper映射语句高阶应用——ResultMap
    SeekBar和RatingBar
    Myeclipse中如何修改Tomcat的端口号
    新浪微博客户端开发之OAuth认证篇
    层层递进Struts1(六)自定义转换器
    CF 13E Holes 【块状链表】
    《mysql必知必会》学习_第13章
  • 原文地址:https://www.cnblogs.com/zhangronghua/p/569039.html
Copyright © 2011-2022 走看看