I can see in the config-file that there are some references to custom Umbraco config files.
How do you write to those config-files in production? Do you use an XML/IO-approach or a umbraco custom class (some kind of ConfigurationManager)?
When people make custom packages, how do they write new settings to their config-files?
I would like to change config setup in production and save it. Ie. for a custom 404 page.
But I went through the umbraco source code and I found out that they are using a mix of IO/Xml and configuration manager, so I have used their approach. Thanks for answering anyway.
internal static void SaveSetting(string key, string value)
{
var fileName = IOHelper.MapPath(string.Format("{0}/web.config", SystemDirectories.Root));
var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace);
var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single();
var setting = appSettings.Descendants("add").FirstOrDefault(s => s.Attribute("key").Value == key);
if (setting == null)
appSettings.Add(new XElement("add", new XAttribute("key", key), new XAttribute("value", value)));
else
setting.Attribute("value").Value = value;
xml.Save(fileName, SaveOptions.DisableFormatting);
ConfigurationManager.RefreshSection("appSettings");
}
But in this particular situation, I have to read/store a custom config setting before the application runs.
UI-O-Matic looks great, I will check it out. Thanks.
How to write to an umbraco config file
Hi there forum.
I can see in the config-file that there are some references to custom Umbraco config files. How do you write to those config-files in production? Do you use an XML/IO-approach or a umbraco custom class (some kind of ConfigurationManager)? When people make custom packages, how do they write new settings to their config-files?
The only reason I see for someone to do this would be to adapt the configuration files values by environment for Devops purpose.
Is it the case for you ?
If yes, which devops tool do you use ? Azure devops, Octopus, Jenkins, other ?
Hi there Ali, thanks for the reply.
I would like to change config setup in production and save it. Ie. for a custom 404 page. But I went through the umbraco source code and I found out that they are using a mix of IO/Xml and configuration manager, so I have used their approach. Thanks for answering anyway.
I don't think it's the right way, the aim of configuration files is to store static values :x
If you want to have dynamic settings, I would recommend using a specific part of content tree or this plugin: https://our.umbraco.com/packages/developer-tools/ui-o-matic/ to store your settings.
Maybe the document types are more releveant as you'd be able to manage access security to the settings tree.
Kr, Ali
But in this particular situation, I have to read/store a custom config setting before the application runs. UI-O-Matic looks great, I will check it out. Thanks.
is working on a reply...