Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
465 views
Welcome To Ask or Share your Answers For Others

1 Answer

In each section, you can define configSource, which can point to an external file path. Here's a simple example:

<connectionStrings configSource="myConnectionStrings.Config" />
<appSettings configSource="myAppSettings.Config" />

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...