網站訪問量統計實現.

來源:互聯網
上載者:User

通過使用者對網站的訪問,來統計該網站的總訪問量.實現起來非常簡單.把每一次訪問的數累加即可.由於資料

更新頻繁,所以資料存放區在文字檔中.每次更新其中的文字檔資料即可.

然後把數字替換成相應圖片.不知道為何,CSDN又不能上傳圖片了.CSDN的blog做得很不穩定..圖略.(非常簡單)

代碼如下;

using  System;
using  System.Collections;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Web;
using  System.Web.SessionState;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.HtmlControls;
using  System.IO;

namespace  Counter
... {
    /**//// <summary>
    /// Test 的摘要說明。
    /// </summary>
    public class Test : System.Web.UI.Page
    ...{
        protected System.Web.UI.WebControls.Label Count;
        long counter=1;
        private void Page_Load(object sender, System.EventArgs e)
        ...{
            // 在此處放置使用者代碼以初始化頁面
            if (!IsPostBack)
            ...{
                Application.Lock();//進行鎖定,防止非同步更新
                string countfile=Server.MapPath("count.txt");
                if(File.Exists(countfile))
                ...{
                    StreamReader sReader=new StreamReader(countfile);
                    string s;
                    long x;
                    s=sReader.ReadLine();
                    if(s!=null )
                    ...{
                        x=Convert.ToInt64(s);
                        counter=x+1;
                    }
                    sReader.Close();
                }
                StreamWriter sWriter=new StreamWriter(countfile);
                sWriter.Write((counter.ToString()));//將long類型轉換為string類型
                sWriter.Flush();
                sWriter.Close();
                Application.UnLock();
                Count.Text=piclong(counter);
            }
        }

        public string piclong(long counter)
        ...{
            string returns="";
            for(int i=1;i<=counter.ToString().Length;i++)
            ...{
                returns+="<td><img src='Image/"+counter.ToString().Substring(i-1, 1)+".gif' width='14' height='19'></td>";
            }
            return returns;
        }

        Web 表單設計器產生的程式碼#region Web 表單設計器產生的程式碼
        override protected void OnInit(EventArgs e)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.