Files
BeWoPlaner/Service/Core/MergedConfig.cs

44 lines
1.1 KiB
C#
Raw Permalink Normal View History

using System;
using System.Configuration;
using System.IO;
using System.Xml;
namespace BeWo.Service.Core
{
public static class MergedConfig
{
2025-06-03 15:46:41 +02:00
public static string GetSetting(WebConfigSetting config)
{
2025-06-03 15:46:41 +02:00
return getSetting(config.ToString());
}
2025-06-03 15:46:41 +02:00
public static string GetSecretSetting(WebSecretConfigSetting webSecretConfigSetting)
{
if (webSecretConfigSetting == WebSecretConfigSetting.None)
throw new ArgumentNullException("webSecretConfigSetting");
2025-06-03 15:46:41 +02:00
return getSecretSetting(webSecretConfigSetting.ToString());
}
private static string getSetting(string key)
{
return ConfigurationManager.AppSettings[key];
}
2025-05-27 10:32:21 +02:00
2025-06-03 15:46:41 +02:00
private static string getSecretSetting(string key)
2025-05-27 10:32:21 +02:00
{
var localConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Web.Secrets.config");
if (!File.Exists(localConfigPath))
return null;
var xml = new XmlDocument();
xml.Load(localConfigPath);
var node = xml.SelectSingleNode($"/appSettings/add[@key='{key}']");
if (node is XmlElement element)
return element.GetAttribute("value");
return null;
}
}
}