gpt4 book ai didi

c# - 通过代码打开机器/基地Web.Config(64位)

转载 作者:太空宇宙 更新时间:2023-11-03 11:29:58 24 4
gpt4 key购买 nike

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

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

  • C:\Windows\Microsoft.NET\Framework\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 = "<title>" + this.comboBox1.Text + "</title>" +
"<artist>" + artist.Text + "</artist>" +
"<price>" + price.Text + "</price>";

root.ReplaceChild(newCd, oldCd);

//save the output to a file
doc.Save(FILE_NAME);

关于c# - 通过代码打开机器/基地Web.Config(64位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8130085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com