我需要在运行时更新.Net exe app.config文件的system.net SectionGroup中的设置。我在运行时没有对原始配置文件的写入权限(我正在开发一个.net dll加载项,该加载项位于应用程序提供的exe文件中,我无法控制),所以我希望能够保存副本并在运行时将exe中的配置替换为修改后的版本。我试过以下,但它不起作用。有什么建议么?在运行时更新app.config system.net设置
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
NetSectionGroup netSectionGroup = config.GetSectionGroup("system.net") as NetSectionGroup;
netSectionGroup.Settings.HttpWebRequest.UseUnsafeHeaderParsing = true;
config.SaveAs(@"C:\ProgramData\test.config", ConfigurationSaveMode.Full);
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @"C:\ProgramData\test.config");
我正在开发一个.Net应用程序(Windows Media Center)的加载项。插件的形式是一个dll .Net程序集,它被加载到由Media Center exe(ehshell.exe)管理的单独主机进程(ehexthost.exe)中。我无法保存到主机进程的原始app.config文件,因为它的位置,因此需要保存到备用路径。另外我想更改system.net SectionGroup而不是AppSettings。谢谢。 – mthornal 2009-06-11 11:23:54