Search code examples
asp.netconfigurationweb-configfilesystemwatcher

How to use real-time configurations in an ASP.NET application without restaring it?


I have an asp.net application which uses session for user management. So if the application is restarted users will loose their works.

I have some components used by this asp.net application and those components (class libraries in Bin folder) have configurations. I want to save configurations of those components somewhere and change them from back-end (administration panel) and the components use the updated configs but still application should not be restarted (changing web.config will result in application restart).

How can I achieve that ?


Solution

  • Put all your configurations in any xml file. This way even of you change the configuration at runtime, the application will not be restarted. Since any changes in web.config will restart the application.

    EDIT:

    I found something, you can add an app.config to your web application and map the app.config to get the settings from there.

    ExeConfigurationFileMap exConfigFile = new ExeConfigurationFileMap();
    exConfigFile.ExeConfigFilename = Server.MapPath("app.config");
    Configuration config = ConfigurationManager.OpenMappedExeConfiguration(exConfigFile, ConfigurationUserLevel.None);
    
    // you can get the appSettings configuration in the app.config by this
    string testConfig = config.AppSettings.Settings["Test"].Value;