日期:2014-05-17 浏览次数:20452 次
protected void Page_Load(object sender, EventArgs e)
{
this.Title = "使用Session对象设计网站计数器";
string FilePath = Server.MapPath("counter.txt");
StreamReader mystr = new StreamReader(FilePath);
int count = int.Parse(mystr.ReadLine());
mystr.Close();
if (Session["counter"] == null)
{
Session["counter"] = "";
count = count + 1;
StreamWriter s = new StreamWriter(FilePath);
s.WriteLine(count);
s.Close();
}
Response.Write("当前SessionID值为:" + Session.SessionID + "<br>");
Response.Write("您是本站第" + count.ToString() + "位访问者");
}
int count=0;
int.TryParse(mystr.ReadLine(),out count);