My asp.net app has is using a web.config for common configuration. I also have a section that maps some data objects to connection strings, and that section is going to be couple thousand of lines. I want to move that section to another config file "dataMappings.config", so I don't bulk up web.config - is there a standard mechanism of accessing that config file?
Thank you, Andrey
In each section, you can define
configSource
, which can point to an external file path. Here's a simple example:Just make sure not to use
.xml
file extension since it can be viewed in a browser..config
will not be served by the web server.Because your config sections are still defined in the web.config (thus pointing to external files), you can access this information via the normal routes (
WebConfigurationManager.AppSettings
,WebConfigurationManager.GetSection
,ConfigurationManager
, or custom section handlers as needed)I used a configuration helper in a shared DLL, and an app.config file in the DLL that uses the Settings.Properties.Default stuff by editing the project and setting the settings tab. It appears that value isn't read unless you recompile, and resync the app.config (in the dll) with the project settings.
This works for me. I don't remember where I got the inspiration. I just include this class in a shared project somewhere. allows any DLL to call its own settings, which allows you to change the dllFile.dll.config entries. I use this for connection strings. The caveat is that in this method, the connection string has to be a type string, and not the special connection string.