爱问知识人 爱问教育 医院库

.net中统计访问次数出现问题

首页

.net中统计访问次数出现问题

string s = "\\controls\\log.txt";
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码

FileStream fs = new FileStream(Server.MapPath(".") + s, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs, Encoding.Default);
StringBuilder sb = new StringBuilder();
string temp = "";
while ((temp = sr.ReadLine()) != null)
sb.Append(temp);
string result = sb.ToString().Trim ();
int count = Convert.ToInt32(result);

Application["count_web"] =count;
Application ["num"] = 1;

}

void Application_End(object sender, EventArgs e)
{
//  在应用程序关闭时运行的代码
System.IO.File.Delete(Server.MapPath(".") + s);
System.IO.File.Create(Server.MapPath(".") + s);
StreamWriter sw = new StreamWriter(Server.MapPath(".") + s);
sw.Write(Application["count_web"].ToString());
sw.Flush();


}

void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码

}

void Session_Start(object sender, EventArgs e)
{
// 在新会话启动时运行的代码
Application.Lock();
Application["count_web"] =Convert .ToInt32 ( Application["count_web"])+1;
Application ["num"] = Convert .ToInt32 ( Application ["num"])+1;
Application.UnLock();    

}

void Session_End(object sender, EventArgs e)
{
// 在会话结束时运行的代码。
// 注意: 只有在  nfig 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
// 或 SQLServer,则不会引发该事件。
Application.Lock();
Application ["num"] = Convert.ToInt32(Application ["num"]) - 1;
Application.UnLock();
}


我建了一个log.txt的文件,用来保存总访问次数。
如上,已经实现了从log.txt中读取总访问次数,但是却无法实现往log.txt中写入总访问次数。
请问这是什么原因了。

提交回答
好评回答
  • 2010-06-10 13:32:41
    提示什么,是不是没有写权限。为什么不用数据库。如果多人同时访问,对log.txt的打开和写入是不是会有冲突呢。

    洪***

    2010-06-10 13:32:41

  • C#/.NET 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):