I am currently working on project using asp.net core v2.0, and in my appsettings.json I have:
"ContextSettings": {
"ConnectionString": "Data Source={base-path}WahupaWeb.sqlite;Version=3;BinaryGUID=True;datetimeformat=CurrentCulture",
"Provider": "System.Data.SQLite.EF6",
"DropCreateDatabaseAlways": "false"
}
I have a scenario where I need to update "data source" of connection string programmatically.
I am reading and trying to update JSON file using this code.
public class FileController : Controller
{
private IConfigurationRoot Configuration { get; set; }
private void ConfigureConnectionString(string dbFileName)
{
var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
.SetBasePath(Environment.CurrentDirectory)
.AddJsonFile("appsettings.json", false, reloadOnChange: true);
Configuration = builder.Build();
Configuration["ContextSettings:ConnectionString"] = sqliteConnectionString;
}
}
But it is not updating the file name "appsettings.json".
How to update appsettings.json file programmatically.