CSDN大虾真多,我好喜欢这里呀。这不,我这又有问题要问了:
这里为什么要将int作个转换?难道Application对象只接收object类型的变量?
 int count = 0;
 object obj = count;
 Application["counter"] = obj;完整代码如下:
public partial class counter : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int count = 0;
            if (Session["OnLine"].ToString() == "true")
            {
                Application.Lock();
                count = (int)Application["counter"];
                count = count + 1;
                object obj = count;
                Application["counter"] = obj;                //将数据记录写入文件
                string strFilePath = Server.MapPath("counter.txt");
                StreamWriter SW = new StreamWriter(strFilePath, false);
                SW.WriteLine(count);
                SW.Close();
                Session["count"] = count.ToString();
                Application.UnLock();
                Session["OnLine"] = "false";
            }
            else
            {
                count = Convert.ToInt32(Session["count"]);
            }          
            string strCounter = count.ToString();
            string imgName;
            Response.Write("您是第");
            for (int i = 0; i < strCounter.Length; i++)
            {
                imgName = strCounter.Substring(i, 1);
                Response.Write(imgName);
            }
            Response.Write("位访问者");
        }
    }
}