通过code打开机/基Web.Config中(64位) [英] Opening the machine/base Web.Config (64bit) through code
问题描述
我期待写code打开并编辑基本的web.config文件的机器(作为一个HttpModule安装程序的一部分)。
我想编辑是在一般位于中的文件:
- C:\\ WINDOWS \\ Microsoft.NET \\框架\\ V2.0.50727 \\ CONFIG \\ web.config中
- C:\\ WINDOWS \\ Microsoft.NET \\ Framework64 \\ V2.0.50727 \\ CONFIG \\ web.config中
如果我用下面的code I可以打开该文件的32位版本:
配置配置= WebConfigurationManager.OpenWebConfiguration(NULL);
我如何打开文件的64位版本? (无论已安装在那里的,即使是在其他地方安装在机器上)。
更新:
有问题的code是,增加了机器的底座web.config中的GAC集引用,HTTP模块和HttpHandler的安装程序。由于模块被设计为一个整个服务器的基础上使用,基地的web.config是把这个最好的地方。我再说一遍:这不是病毒的创作为提出意见。张女士说,你需要运行提升到接触这些文件应该有助于使这个这个假设错误的。
XmlTextReader的读者= XmlTextReader的新(FILE_NAME);
XmlDocument的DOC =新的XmlDocument();
doc.Load(读卡器);
reader.Close();//选择与匹配的标题CD节点
XmlNode的oldCd;
XmlElement的根= doc.DocumentElement;
oldCd = root.SelectSingleNode(/目录/ CD [标题='+ oldTitle +']);的XmlElement newCd = doc.CreateElement(CD);
newCd.SetAttribute(国家,country.Text);newCd.InnerXml =<标题>中+ this.comboBox1.Text +< /标题>中+
<&艺术家GT; + artist.Text +< /艺术家>中+
<价格> + price.Text +< /价格>,root.ReplaceChild(newCd,oldCd);//输出保存到一个文件
doc.Save(FILE_NAME);
I am looking to write code to open and edit the base web.config files for a machine (as part of an installer for an HttpModule).
the files i want to edit are located commonly at:
- C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config
- C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG\web.config
If i use the following code i can open the 32bit version of the file:
Configuration configuration = WebConfigurationManager.OpenWebConfiguration(null);
How do i open the 64 bit version of the file? (regardless of where it has been installed, even if it is installed elsewhere on a machine).
UPDATE: The code in question is for an installer that adds an GAC assembly reference, HttpModule, and HttpHandler to the base web.config of a machine. As the Module is designed to be used on a "whole server" basis, the base web.config is the best place to put this. I REPEAT: THIS IS NOT FOR THE CREATION OF A VIRUS AS PROPOSED IN COMMENTS. The very fact that you need to be running elevated to touch these files should help make this this assumption false.
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);
这篇关于通过code打开机/基Web.Config中(64位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!