本地计数器

来源:互联网 发布:马鹿野郎 知乎 编辑:程序博客网 时间:2024/05/02 01:03
#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
原创粉丝点击