I have a small .NET Core console app which has an appsettings.json
file containing different configuration sections and some of the values contain accents (for
Inspired by Deep Dive into Microsoft Configuration, I found a solution. My solution is to combine the use of json and xml.
In Your Program.cs, You need to add the load of xml. Example where I map settings to a POCO:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(AddDbConfiguration)
.UseStartup();
private static void AddDbConfiguration(WebHostBuilderContext context, IConfigurationBuilder builder)
{
var configuration = builder.Build();
builder.AddXmlFile("appsettings.xml");
}
My xml file:
Specialskolekørsel
1
True
My ConfigureServices:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.Configure(Configuration.GetSection(nameof(ConfigSettings)));
}
My Controller:
public HomeController(IOptions config)
{
Database = config.Value.Database;
}
Now the danish letter ø shows as expected. I hope You will find this useful.