小编mth*_*nal的帖子

在运行时更新app.config system.net设置

我需要在运行时更新.Net exe app.config文件的system.net SectionGroup中的设置.我没有在运行时对原始配置文件的写访问权限(我正在开发一个.Net dll加载项,它由我无法控制的应用程序提供的exe托管)所以我希望保存一份副本的文件,并在运行时用修改后的版本替换exe中的配置.我尝试过以下但是没有用.有什么建议?

    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");
Run Code Online (Sandbox Code Playgroud)

.net c# system.net app-config

23
推荐指数
1
解决办法
4万
查看次数

标签 统计

.net ×1

app-config ×1

c# ×1

system.net ×1