Which service am I to retrieve from GetRequiredService?
There is a GlobalSettings configuration class for that config section but I must be doing things incorrectly since my runtime change doesn't seem to override the appsettings.json values.
This is what DOESNT work:
var globalSection = umbracoBuilder.Config.GetSection("Umbraco:CMS:Global").Get<GlobalSettings>();
if (globalSection != null)
{
globalSection.ReservedPaths = globalSection.ReservedPaths.Replace("somevalue", "someothervalue");
umbracoBuilder.Config.GetSection("Umbraco:CMS:Global:ReservedPaths").Value = globalSection.ReservedPaths;
}
You can use PostConfigure method in a composer to change the settings values (this is called when the site loads and if the file is changed, and the settings reloaded).
e.g.
public class MyReservePathComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.PostConfigure<GlobalSettings>(settings =>
{
settings.ReservedPaths = "one, two, three";
});
}
}
as a composer it will get wrapped into umbraco and called when the site starts.
I dropped in this composer class but its 'Compose' method didn't seem to get hit. I'm using Umbraco 14. I haven't used a composer before, but I thought that it would be found and registered automatically on startup. Is that correct?
Changing Configuration From Code Instead of AppSettings.json?
I want to change the Umbraco/CMS/Global/ReservedPaths configuration setting from inside my program.cs instead of doing it in appsettings.json.
Why? I have so many reserved paths that the json is getting unwieldy
Does anybody know if this is possible? It seems like during startup in program.cs it would be a good opportunity.
Which service am I to retrieve from GetRequiredService?
There is a GlobalSettings configuration class for that config section but I must be doing things incorrectly since my runtime change doesn't seem to override the appsettings.json values.
This is what DOESNT work:
You can use PostConfigure method in a composer to change the settings values (this is called when the site loads and if the file is changed, and the settings reloaded).
e.g.
as a composer it will get wrapped into umbraco and called when the site starts.
Thanks Kevin,
I dropped in this composer class but its 'Compose' method didn't seem to get hit. I'm using Umbraco 14. I haven't used a composer before, but I thought that it would be found and registered automatically on startup. Is that correct?
is working on a reply...