update app.config file programmatically with ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

后端 未结 2 1254
心在旅途
心在旅途 2020-12-01 11:21

update app.config file programmatically with

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

相关标签:
2条回答
  • 2020-12-01 11:56

    The ProjectBase.Data.OpenSessionInViewSection indicates that there is already a custom config section defined that will allow access to the config settings. It may, however be protected or internal to NHibernate.

    See if you can reference that class to access the settings.

    You could also create a custom configuration section yourself, however it would cause NHibernate to be improperly configured since it would not be able to load the config section properly.

    see How to: Create Custom Configuration Sections Using ConfigurationSection

    0 讨论(0)
  • 2020-12-01 12:05

    You can use the following code:

    private void UpdateConfig(string key, string value, string fileName)
    {
        var configFile = ConfigurationManager.OpenExeConfiguration(fileName);
        configFile.AppSettings.Settings[key].Value = value;
    
        configFile.Save();
    }
    

    Where: fileName is the full path + application name (c:\project\application.exe)

    In your case, change the AppSetting by Sections:

    configFile.Sections["nhibernateSettings"]
    
    0 讨论(0)
提交回复
热议问题