语言c# 访问量计数器 根目录下使用count.dat文件存放网站访问的总人数和在线人数
  global.asa怎么写   
     页面上怎样显示(您是第 位访问者 在线人数 位)
 
最好给我个全的源代码,谢谢各位大大!!!!!

解决方案 »

  1.   

    可以到google.com 或者baidu.com搜索啊
    要用到application_begain和session_begin方法
      

  2.   

    只告诉你代码在 Global.asax 里面写,具体的到GOOGLE  或 BAIDU去找吧!
      

  3.   

    protected void Application_Start(Object sender, EventArgs e) +1
    protected void Session_Start(Object sender, EventArgs e) +1
    protected void Session_End(Object sender, EventArgs e) -1
      

  4.   

    application_begain和session_begin方法
      

  5.   

    访问总人数最好写进数据库..在线人数...可以先在application 里初始化 比如:
    protected void Application_Start(object sender, EventArgs e)
    {
         Application["count_user"] = 0;
    }
    然后用户访问创建session时+1   session失效时-1
    protected void Session_Start(object sender, EventArgs e)
    {
         Application["count_user"] = Convert.ToInt32(Application["count_user"]) + 1;
    }
    protected void Session_End(object sender, EventArgs e)
    {
         Application["count_user"] = Convert.ToInt32(Application["count_user"]) - 1;
    }
      

  6.   

    网站根目录增加一个IPRecord.txt的文件  private static string iprecordPath = string.Empty;
     protected void Application_EndRequest(object sender, EventArgs e)
        {
            if (iprecordPath == string.Empty)
            {
                iprecordPath = Server.MapPath(".") + "/IPRecord.txt";
            }
            if (Request.Cookies[""] == null)
            {
                    HttpCookie  = new HttpCookie("");
                    .Value = "1";
                    Response.SetCookie();
                    //记录IP
                    try
                    {
                        string IPRecord = Server.MapPath(".") + "/IPRecord.txt";
                        string Record = string.Format("IP:{0}  DateTime:{1} \r\n", Request.UserHostAddress, System.DateTime.Now);
                        FileStream fs = File.Open(IPRecord, FileMode.Append, FileAccess.Write, FileShare.None);
                        byte[] buff = System.Text.Encoding.Default.GetBytes(Record);
                        fs.Write(buff, 0, buff.Length);
                        fs.Close();
                    }
                    catch
                    {  
                        //无处理
                    }
            }
        }
      

  7.   

    http://download.csdn.net/source/179050#aa
      

  8.   

    你也想找源代码啊,哈哈
    下面两个msdn里的课程里,可能是第一个,也可能是第二个,里有计数器的源代码,还有教程,你试试看。
    http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032328332&EventCategory=3&culture=zh-CN&CountryCode=CN
    http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032328088&EventCategory=3&culture=zh-CN&CountryCode=CN