我在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>

解决方案 »

  1.   

    不知道你否真懂读写xml!!去这里看看吧!:http://www.aspxcs.net/HTML/XMLBC/List_11.html
      

  2.   

    不是很懂,正在学习,我按照这样写
            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"));还是一样的错误
      

  3.   

     if (xe.Name == "AllCount") 
                {                 xe.InnerText = Convert.ToString((Convert.ToInt32(xe.InnerText.ToString()) + 1)); 
                     xmldoc.Save(Server.MapPath("Count.xml")); 
                } 
                break; 
            }        
      

  4.   

    呵呵,不能在这个事件中写,在下面的事件中写:
    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"));//写 
            

      

  5.   

    void Application_Start(object sender, EventArgs e)可以记录访问用户的历史数量
    void Application_BeginRequest(object sender, EventArgs e)记录浏览量
    另外,你无法写入,可能是没有写入权限。