Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正在更改appSettings网络配置上的值。仅适用于第二页加载_C#_Asp.net_Web Config_Appsettings_Webconfigurationmanager - Fatal编程技术网

C# 正在更改appSettings网络配置上的值。仅适用于第二页加载

C# 正在更改appSettings网络配置上的值。仅适用于第二页加载,c#,asp.net,web-config,appsettings,webconfigurationmanager,C#,Asp.net,Web Config,Appsettings,Webconfigurationmanager,我运行了以下代码。在我的网络配置中更改应用程序设置。但我得多加一页才能“变魔术” 第一。页面加载。使用以前的设置。 第二页加载。好的 我把它放在页面\u PreInit中: Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~"); AppSettingsSection appSettings = (AppSettingsSection)configuration.GetSect

我运行了以下代码。在我的网络配置中更改应用程序设置。但我得多加一页才能“变魔术”

第一。页面加载。使用以前的设置。 第二页加载。好的

我把它放在
页面\u PreInit
中:

    Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
    AppSettingsSection appSettings = (AppSettingsSection)configuration.GetSection("appSettings");

    appSettings.Settings["FileManager"].Value = "newValue";
    configuration.Save();

如果您指的是“首页加载”这段代码之后运行的代码,这是正常现象。

配置文件只是在请求之后(和preInit之前)使用。

我认为唯一的解决办法是增加页面负载。

谢谢您的回复。这听起来像是忍者的把戏。。。你能告诉我如何做这个程序吗?你可以使用Response.Redirect(“Page url.aspx?back=currentpageurl”)并将其设置为返回一个请求参数,如“currentpage.aspx?isback=1”,然后在页面中检查该参数以运行你想要的代码