protected void Application_Start(Object sender, EventArgs e) ...{ uint count=0; StreamReader srd; string file_path=Server.MapPath ("Counter/counter.txt"); srd=File.OpenText (file_path); while(srd.Peek ()!=-1) ...{ string str=srd.ReadLine (); count=UInt32.Parse (str); } object obj=count; Application["counter"]=obj; srd.Close (); } protected void Session_Start(Object sender, EventArgs e) ...{ Application.Lock (); //数值累加,注意这里使用了装箱(boxing) uint jishu=0; jishu=(uint)Application["counter"]; jishu=jishu+1; object obj=jishu; Application["counter"]=obj; //将数据记录写入文件 string file_path=Server.MapPath ("Counter/counter.txt"); StreamWriter fs=new StreamWriter(file_path,false); fs.WriteLine (jishu); fs.Close (); Application.UnLock (); ZzbDbproClass m_Dbpro=new ZzbDbproClass(); string m_IPAddress=m_Dbpro.G_User_IP(); m_Dbpro.Add_OT_SiteLog( System.DateTime.Now, m_IPAddress, System.DateTime.Now.Month, System.DateTime.Now.Year); m_Dbpro.Upt_OT_SiteCount(int.Parse(Application["counter"].ToString()),""); } protected void Application_End(Object sender, EventArgs e) ...{ //装箱 uint js=0; js=(uint)Application["counter"]; //object obj=js; //Application["counter"]=js; //将数据记录写入文件 string file_path=Server.MapPath ("Counter/counter.txt"); StreamWriter fs=new StreamWriter(file_path,false); fs.WriteLine(js); fs.Close (); } //禁cacheResponse.Buffer=true; Response.ExpiresAbsolute=DateTime.Now.AddSeconds(-1); Response.Expires=0; Response.CacheControl="no-cache";