我在Global.asax文件的
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(Server.MapPath("Count.xml"));//读
Application["Count"] = ds.Tables["Count"].Rows[0]["AllCount"];
ds.Tables["Count"].Rows[0]["AllCount"] = Convert.ToInt32(ds.Tables["Count"].Rows[0]["AllCount"]) + 1;
ds.WriteXml(Server.MapPath("Count.xml"));//写
}
这里写的一段读写xml文件,读没问题,但是写的时候就报错了,说拒绝访问Count.xmlCount.xml文件内容如下
<?xml version="1.0" encoding="utf-8" ?>
<Count>
<AllCount>36</AllCount>
</Count>
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(Server.MapPath("Count.xml"));//读
Application["Count"] = ds.Tables["Count"].Rows[0]["AllCount"];
ds.Tables["Count"].Rows[0]["AllCount"] = Convert.ToInt32(ds.Tables["Count"].Rows[0]["AllCount"]) + 1;
ds.WriteXml(Server.MapPath("Count.xml"));//写
}
这里写的一段读写xml文件,读没问题,但是写的时候就报错了,说拒绝访问Count.xmlCount.xml文件内容如下
<?xml version="1.0" encoding="utf-8" ?>
<Count>
<AllCount>36</AllCount>
</Count>
System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
xmldoc.Load(Server.MapPath("Count.xml"));
System.Xml.XmlNodeList nodelist = xmldoc.SelectSingleNode("Count").ChildNodes;
foreach (System.Xml.XmlNode xn in nodelist)
{
System.Xml.XmlElement xe = (System.Xml.XmlElement)xn; if (xe.Name == "AllCount")
{ xe.InnerText = Convert.ToString((Convert.ToInt32(xe.InnerText.ToString()) + 1));
break;
}
break;
} xmldoc.Save(Server.MapPath("Count.xml"));还是一样的错误
{ xe.InnerText = Convert.ToString((Convert.ToInt32(xe.InnerText.ToString()) + 1));
xmldoc.Save(Server.MapPath("Count.xml"));
}
break;
}
void Application_BeginRequest(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(Server.MapPath("Count.xml"));//读
Application["Count"] = ds.Tables["Count"].Rows[0]["AllCount"];
ds.Tables["Count"].Rows[0]["AllCount"] = Convert.ToInt32(ds.Tables["Count"].Rows[0]["AllCount"]) + 1;
ds.WriteXml(Server.MapPath("Count.xml"));//写
}
void Application_BeginRequest(object sender, EventArgs e)记录浏览量
另外,你无法写入,可能是没有写入权限。