In an ASP.NET project I'd like to save and retrieve the configuration from another server. The appsettings is saved as a file in a asp.net project. However, I'd like the configuration saved to an external server. This way I can retrieve the configuration across several projects. Is this possible with either asp.net or asp.net core?
Asked
Active
Viewed 160 times
0
-
If two projects are using the same configuration values then better they are put in a common place such as database or common file which is accessible by both the projects. – Chetan Mar 20 '18 at 03:28
-
@ChetanRanpariya how would you bind a config from a database? – Luke101 Mar 20 '18 at 03:30
-
In simple terms, do not use configuration file. Store the configuration values in database table with two columns ConfigKey and ConfigValue. And retrieve them from the table when you need to use them from both the projects. Then only configuration both the projects need have is same database connection string. – Chetan Mar 20 '18 at 03:33
-
@ChetanRanpariya great solution. Ill wait a bit to see if there are any other solutions. if not Ill accept your answer. – Luke101 Mar 20 '18 at 03:40
-
Its really easy just use an XML file, don't bother with the Configuration classes in the BCL. https://stackoverflow.com/questions/14226653/maintaining-multiple-settings-files?rq=1 or use the Configuration: https://stackoverflow.com/a/31602736/495455 – Jeremy Thompson Mar 20 '18 at 03:50
-
Have a look at [this question](https://stackoverflow.com/q/6940004/1429080) and the accepted answer. – user1429080 Mar 20 '18 at 08:25
1 Answers
1
The new/best approach in ASP.NET Core to deal with configuration is via Configuration API.
The main idea that you register needed configuration provider(s) that know how to read settings from the file, database, Azure Key Vault, etc (you even could create your own custom provider).
Configuration API then internally uses those providers to populate collection (actually dictionary) of settings. This collection then accessible to you via IConfiguration
interface. There is also Options pattern that help to create and fill DTO option classes to represent groups of related settings.

Set
- 47,577
- 22
- 132
- 150