#region 计数器 if (!Page.IsPostBack) { string countFile = Server.MapPath("counter.txt"); int count = 1; if (!File.Exists(countFile)) { StreamWriter sw = File.CreateText(countFile); sw.WriteLine("1"); sw.Flush(); sw.Close(); } else { StreamReader srReadLine = new StreamReader(countFile, System.Text.Encoding.Default); if (Session["VisitorNum"] == null) { count = Convert.ToInt32(srReadLine.ReadLine()) + 1; srReadLine.Close(); try { StreamWriter sw = File.CreateText(countFile); sw.WriteLine(count.ToString()); sw.Flush(); sw.Close(); } catch (Exception ex) { Response.Write(ex.Message); } Session["VisitorNum"] = "wei"; } else { count = Convert.ToInt32(srReadLine.ReadLine()); srReadLine.Close(); } this.lblVistorNum.Text = count.ToString(); } } #endregion
本地计数器
最新推荐文章于 2020-05-13 18:30:33 发布