要求  :用一个文本文件保存访问的数字 页面每刷新一次: 将文本的数字加1写入, 再从文本文件中读出来

解决方案 »

  1.   

    在Global.asax 中设置 
     void Application_Start(object sender, EventArgs e) 
        {
            // 在应用程序启动时运行的代码
             //Application[“num”]用于存储访问量的值
                 Application["num"]=从数据库中取值
        }
     void Session_Start(object sender, EventArgs e) 
        {
            // 在新会话启动时运行的代码
            Application["num"]=(int.parse(Application["num"].toString())+1).ToString();
        }
     void Application_End(object sender, EventArgs e) 
        {
            //  在应用程序关闭时运行的代码
            //在此处再将 Application["num"]中的值保存到数据库中
        }
      

  2.   

    在Global.asax 中的Session_Start(object sender, EventArgs e)方法里写
     void Session_Start(object sender, EventArgs e) 
        { 
            // 在新会话启动时运行的代码 
            Application["在线人数"]=(int.parse(Application["在线人数"].toString())+1).ToString(); 
        } 
      

  3.   

    2楼的 使用Application 时要锁定的,使用完在释放void Session_Start(object sender, EventArgs e) 
        { 
            // 在新会话启动时运行的代码 
            Application.Lock();
            Application["num"]=(int.parse(Application["num"].toString())+1).ToString(); 
           Application.UnLock();
        } 
      

  4.   

    用文本会不会太慢了....
    写在application里吧.真要保存,定期写文本吧.
      

  5.   

    写在application里吧,读写文本太费资源了。application里结束时写入数据库或写入文本
      

  6.   

    private void menuItem2_Click(object sender, System.EventArgs e)
    {//浏览文本文件
    this.openFileDialog1.ShowDialog();
    string MyFileName=this.openFileDialog1.FileName;
    if(MyFileName.Trim()=="")
    return;
    StreamReader MyReader=null;
    try
    {
     MyReader=new StreamReader(MyFileName,System.Text.Encoding.Default);
    this.richTextBox1.Text=MyReader.ReadToEnd();
    }
    catch(Exception Err)
    {
    MessageBox.Show("读文本文件发生错误!请检查源文件是否是文本文件?","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    return;
    }
    finally
    {
    if(MyReader!=null)
    {
    MyReader.Close();
    }
    }
    }
    private void menuItem9_Click(object sender, System.EventArgs e)
    {//保存文本文件
    this.saveFileDialog1.ShowDialog();
    string MyFileName=this.saveFileDialog1.FileName;
    if(MyFileName.Trim()=="")
    return;
    StreamWriter MyWriter=null;
    try
    {
    MyWriter=new StreamWriter(MyFileName,false,System.Text.Encoding.Default);
    MyWriter.Write(this.richTextBox1.Text);
    }
    catch(Exception Err)
    {
    MessageBox.Show("写文本文件发生错误!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    return;
    }
    finally
    {
    if(MyWriter!=null)
    {
    MyWriter.Close();
    }
    }
    }
    winfrom 的代码..都是C#语言..做参考...
      

  7.   


    用这个获得每个时间段的值..定时读写一文本就行....我新手...就不太了解.net网页..
      

  8.   

    Application.Lock();
            Application["num"]=(int.parse(Application["num"].toString())+1).ToString(); 
           Application.UnLock();