0

Is there any way to edit value inside appsetting.json using controller?

So, here is the appsetting.json:

{
    "Person": {
    "p1": "test1",
    "p2": "test2",
    "p3": "test3"
    }
}

and this is the class:

public class
{
    public string p1{ get; set; }

    public string p2{ get; set; }

    public string p3{ get; set; }
}

I do some research but no clue. I just find how to read the value of appsetting.json. What I want is to edit the value from controller and save it.

ivorish
  • 29
  • 2
  • 10
  • 1
    Possible duplicate of [ASP.NET Core appsettings.json update in code](https://stackoverflow.com/questions/41653688/asp-net-core-appsettings-json-update-in-code) – Ned Howley Jul 28 '17 at 12:25

1 Answers1

-1

Try

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
            config.AppSettings.Settings["p1"].Value = "test1";       
            config.AppSettings.Settings["p2"].Value = "test2";  
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");