Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // seed default data if not exists
- void seedRootData(string x)
- {
- IConfiguration rtInf = Configuration.GetSection("RootUser");
- var rootRaw = rtInf.GetValue<string>("Raw");
- if (rootRaw == "True")
- {
- //storage of inital appsettings.json rootuser info
- string usrPass = rtInf.GetValue<string>("Password");
- string usrEmail = rtInf.GetValue<string>("Email");
- var json = System.IO.File.ReadAllText("appsettings.json");
- //Optional -- create a backup of appsettings.json
- using (StreamWriter writer = new StreamWriter("appsettings.json.bac"))
- {
- writer.WriteLine(json);
- }
- JObject configJson = JObject.Parse(json);
- configJson["RootUser"]["Raw"] = "false";
- //replace "test2" with password data
- configJson["RootUser"]["Password"] = "test2";
- var newConfig = JObject.FromObject(configJson).ToString();
- using (StreamWriter writer = new StreamWriter("appsettings.json.tmp"))
- {
- writer.WriteLine(newConfig);
- }
- //if no backup, replace backup file with 'null'
- File.Replace(@"appsettings.json.tmp", @"appsettings.json", @"appsettings.json.bac");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement