ConfigurationManager doesn't save settings

前端 未结 3 1927
孤街浪徒
孤街浪徒 2020-11-27 07:27

Here is the code I\'m using:

private void SaveConfiguration()
{
    if (txtUsername.Text != \"\" && txtPassword.Text != \"\")
    {
        Configura         


        
3条回答
  •  隐瞒了意图╮
    2020-11-27 08:11

    When you run your application with F5,

    • your code is compiled,
    • the executable is copied to the bin or bin\Debug subdirectory of your source code directory,
    • your app.config is copied as yourexecutable.exe.config into that directory, and
    • your executable is started in that directory.

    Thus, your application uses the yourexecutable.exe.config in the bin or bin\Debug directory, and it is there that ConfigurationManager saves the changes, not in your source code directory. This won't be an issue after deploying your application, because then, changes will go to yourexecutable.exe.config in the deployment directory, which is what you want.

提交回复
热议问题