访问被拒绝StreamWriter sw = File.CreateText(Server.MapPath("UserCounter.txt"));
我想统计站点的访问量,在Global里写:
protected void Application_Start(Object sender, EventArgs e)
{
string file=Server.MapPath("UserCounter.txt");
if(File.Exists(file))
{
StreamReader sr = File.OpenText(file);
Application["userCounter"] = Int32.Parse(sr.ReadLine());
sr.Close();
}
else
{
Application["userCounter"] = 1000;
}
}
protected void Session_Start(Object sender, EventArgs e)
{
Application.Lock();
Application["userCounter"] = (int)Application["userCounter"] + 1;
StreamWriter sw = File.CreateText(Server.MapPath("UserCounter.txt"));//这句报错
sw.WriteLine((int)Application["userCounter"]);
sw.Close();
Application.UnLock();
}
报错是访问被拒绝,Server.Mapath得到的路径是UserCounter.txt的路径,路径是正确的,可是为什么就报错呢,大家给看看