ASP.NET Core appsettings.json update in code

后端 未结 9 2019
小鲜肉
小鲜肉 2020-12-13 01:54

I am currently working on project using asp.net core v1.1, and in my appsettings.json I have:

\"AppSettings\": {
   \"AzureConnectionKey\": \"***\",
   \"Azu         


        
9条回答
  •  情话喂你
    2020-12-13 02:37

    Basically you can set the values in IConfiguration like this:

    IConfiguration configuration = ...
    // ...
    configuration["key"] = "value";
    

    The issue there is that e.g. the JsonConfigurationProvider does not implement the saving of the configuration into the file. As you can see in the source it does not override the Set method of ConfigurationProvider. (see source)

    You can create your own provider and implement the saving there. Here (Basic sample of Entity Framework custom provider) is an example how to do it.

提交回复
热议问题