博客中,怎样统计多少人看过我的页面,统计多少人看过我的文章。高手帮忙啊

解决方案 »

  1.   

    Global.asax里的代码
    当服务器关闭时不能保存人数,因此用一个记事本来记录
    在工程目录下新建一个count.txt文件保存人数统计                protected void Application_Start(object sender, EventArgs e)
            {
                uint count = 0;
                StreamReader srd;
                //取得文件的实际路径 
                string file_path = Server.MapPath("count.txt");
                //打开文件进行读取 
                srd = File.OpenText(file_path);
                while (srd.Peek() != -1)
                {
                    string str = srd.ReadLine();
                    count = UInt32.Parse(str);
                }
                object obj = count;
                Application["count"] = obj;
                srd.Close();         }        protected void Session_Start(object sender, EventArgs e)
            {
                Application.Lock();
                //数值累加
                uint jishu = 0;
                jishu = (uint)Application["count"];
                jishu = jishu + 1;
                object obj = jishu;
                Application["count"] = obj;
                //将数据记录写入文件 
                string file_path = Server.MapPath("count.txt");
                StreamWriter fs = new StreamWriter(file_path, false);
                fs.WriteLine(jishu);
                fs.Close();
                Application.UnLock(); 
            }        protected void Application_BeginRequest(object sender, EventArgs e)
            {        }        protected void Application_AuthenticateRequest(object sender, EventArgs e)
            {        }        protected void Application_Error(object sender, EventArgs e)
            {        }        protected void Session_End(object sender, EventArgs e)
            {        }        protected void Application_End(object sender, EventArgs e)
            {
                //装箱 
                uint js = 0;
                js = (uint)Application["count"];
                //object obj=js; 
                //Application["counter"]=js; 
                //将数据记录写入文件 
                string file_path = Server.MapPath("count.txt");
                StreamWriter fs = new StreamWriter(file_path, false);
                fs.WriteLine(js);
                fs.Close();         }
      

  2.   

    谢谢wuzexing的帮忙,我的用户登录部分是用MemberShip做的,统计时可以用以上代码吗