0
How to update values into appsetting.json in asp.net application by using c# code?
I know this problem solution is so important so post qustions and their best answer with the code. If you have best answer for this qustions so please post on below answer section it's help lot's of programmers and me. Thank you
1 Resposta
0
it's simply run console application that reads application settings, adds a new setting, and updates an existing setting. and after update refresh the application on server without closed application.
static void AddUpdateAppSettings(string key, string value)
{
try
{
var configFile = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
var settings = configFile.AppSettings.Settings;
if (settings[key] == null)
{
settings.Add(key, value);
}
else
{
settings[key].Value = value;
}
configFile.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
}
catch (ConfigurationErrorsException ex)
{
Console.WriteLine("Error writing app settings. Error: "+ ex.Message);
}
}