《ASP.NET1200例》统计网站访问量源代码
2013-11-26 10:19
441 查看
void Application_Start(object sender, EventArgs e)
{
//在应用程序启动时运行的代码
int count=0;
System.IO.StreamReader srd;
string filepath = Server.MapPath("counter.txt");
srd = System.IO.File.OpenText(filepath);
while (srd.Peek() != -1)
{
string str = srd.ReadLine();
count = int.Parse(str);
}
srd.Close();
object obj = count;
Application["counter"] = obj;
}
void Application_End(object sender, EventArgs e)
{
//在应用程序关闭时运行的代码
int stat = 0;
stat = (int)Application["counter"];
string filepath = Server.MapPath("counter.txt");
System.IO.StreamWriter srw = new System.IO.StreamWriter(filepath, false);
srw.WriteLine(stat);
srw.Close();
}
void Application_Error(object sender, EventArgs e)
{
//在出现未处理的错误时运行的代码
}
void Session_Start(object sender, EventArgs e)
{
//在新会话启动时运行的代码
Application.Lock();
int stat = 0;
//获取Applicat对象中保存的网站总访问量
stat = (int)Application["counter"];
stat += 1;
object obj = stat;
Application["counter"] = obj;
string filepath = Server.MapPath("counter.txt");
System.IO.StreamWriter srw = new System.IO.StreamWriter(filepath, false);
srw.WriteLine(stat);
srw.Close();
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
//在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式
//设置为 StateServer 或 SQLServer,则不会引发该事件。
}
出错: string filepath = Server.MapPath("counter.txt");
未找到引用对象实例,找不路径counter.txt
解决:Server.MapPath读取出来的路径是带有\\的,一开始我以为是需要把路径转义
最后发现,是本地创建的counter.txt是隐藏了后缀名的,也就是本地实际创建的文件时counter.txt.txt于是报错
{
//在应用程序启动时运行的代码
int count=0;
System.IO.StreamReader srd;
string filepath = Server.MapPath("counter.txt");
srd = System.IO.File.OpenText(filepath);
while (srd.Peek() != -1)
{
string str = srd.ReadLine();
count = int.Parse(str);
}
srd.Close();
object obj = count;
Application["counter"] = obj;
}
void Application_End(object sender, EventArgs e)
{
//在应用程序关闭时运行的代码
int stat = 0;
stat = (int)Application["counter"];
string filepath = Server.MapPath("counter.txt");
System.IO.StreamWriter srw = new System.IO.StreamWriter(filepath, false);
srw.WriteLine(stat);
srw.Close();
}
void Application_Error(object sender, EventArgs e)
{
//在出现未处理的错误时运行的代码
}
void Session_Start(object sender, EventArgs e)
{
//在新会话启动时运行的代码
Application.Lock();
int stat = 0;
//获取Applicat对象中保存的网站总访问量
stat = (int)Application["counter"];
stat += 1;
object obj = stat;
Application["counter"] = obj;
string filepath = Server.MapPath("counter.txt");
System.IO.StreamWriter srw = new System.IO.StreamWriter(filepath, false);
srw.WriteLine(stat);
srw.Close();
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
//在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式
//设置为 StateServer 或 SQLServer,则不会引发该事件。
}
出错: string filepath = Server.MapPath("counter.txt");
未找到引用对象实例,找不路径counter.txt
解决:Server.MapPath读取出来的路径是带有\\的,一开始我以为是需要把路径转义
最后发现,是本地创建的counter.txt是隐藏了后缀名的,也就是本地实际创建的文件时counter.txt.txt于是报错
相关文章推荐
- 手机网站开发相关介绍
- Web网站服务(二)
- Web网站服务(一)
- 网站静态页面/register更改要求
- PHP识别网站访问来源是电脑还是手机
- 查看网站信息
- www.shendoushi.net --有趣的笑话网站 我认为java只是一个氛围
- win2003 sp2+iis 6.0上部署.net 2.0和.net 4.0网站的方法
- DEDECMS网站数据备份还原教程
- 架构师“集装箱式”抽象视角的演练
- 架构师“集装箱式”抽象视角的演练
- java分布式通信系统(J2EE分布式服务器架构)
- 免费素材网站
- We7网站群的建设模式搭建政府网站
- 强化县级政府信息化建设
- 采用什么架构,才能够承受大访问量
- 网站架构设计的误区
- weblogic应用服务器
- 后台架构
- 架构设计:生产者/消费者模式:双缓冲区