通过代码打开机器/基础Web.Config(64位)

我期待编写代码来打开和编辑机器的基本web.config文件(作为HttpModule安装程序的一部分)。

我想编辑的文件通常位于:

  • C:\ WINDOWS \ Microsoft.NET \框架\ V2.0.50727 \ CONFIG \ web.config中
  • C:\ WINDOWS \ Microsoft.NET \ Framework64 \ V2.0.50727 \ CONFIG \ web.config中

如果我使用以下代码,我可以打开该文件的32位版本:

Configuration configuration = WebConfigurationManager.OpenWebConfiguration(null); 

如何打开文件的64位版本? (无论它安装在何处,即使它安装在机器的其他地方)。

更新:有问题的代码是安装程序,它将GAC程序集引用,HttpModule和HttpHandler添加到计算机的基本web.config中。 由于模块设计用于“整个服务器”,因此基本web.config是放置它的最佳位置。 我重申:这不是建议在评论中提出的病毒。 你需要提升以触摸这些文件的事实应该有助于使这个假设成为假。

 XmlTextReader reader = new XmlTextReader(FILE_NAME); XmlDocument doc = new XmlDocument(); doc.Load(reader); reader.Close(); //Select the cd node with the matching title XmlNode oldCd; XmlElement root = doc.DocumentElement; oldCd = root.SelectSingleNode("/catalog/cd[title='" + oldTitle + "']"); XmlElement newCd = doc.CreateElement("cd"); newCd.SetAttribute("country",country.Text); newCd.InnerXml = "" + this.comboBox1.Text + "" + "" + artist.Text + "" + "" + price.Text + ""; root.ReplaceChild(newCd, oldCd); //save the output to a file doc.Save(FILE_NAME);