Web.Secrets.config -> eigene Config, welche nicht ins git kommt. Anleitung unter Web.Secrets.config.template

This commit is contained in:
2025-05-05 13:27:22 +02:00
parent 1a3521a531
commit 87445a86b3
7 changed files with 46 additions and 2 deletions

1
.gitignore vendored
View File

@@ -5,6 +5,7 @@ DebugConfig.txt
Host/Multitenancy/demo.config
*.log.txt
*temp.txt
*.Secrets.config
# Folder
bin[Rr]elease/

View File

@@ -457,6 +457,8 @@
<Content Include="Scripts\jquery-3.7.1.slim.min.map" />
<Content Include="Scripts\jquery-3.7.1.min.map" />
<Content Include="Scripts\jquery.mobile-1.4.5.min.map" />
<None Include="Web.Secrets.config.template" />
<None Include="Web.Secrets.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="Admin.aspx.cs">

View File

@@ -0,0 +1,10 @@
//------------------------------------------------------------------------------
// Installation:
// Einfach diese Datei kopieren und den Kommentar hier oben entfernen.
// Ggf. um fehlende API Keys ergänzen
//------------------------------------------------------------------------------
<appSettings>
<add key="OpenWebUIKey" value=""/>
</appSettings>

View File

@@ -307,7 +307,6 @@
<add key="SendMailModuleGkvReceiver" value="dakota.exchange@ownsoft.de" />
<add key="OpenWebUIUrl" value="https://owui1.ownsoft.de/"/>
<add key="OpenWebUIKey" value="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjMyNzJlZjc5LWRmZjEtNDdjYS05NWNlLWZhNjk1ZDdjZGQ4NCJ9.mhQZvSx_mY18J9nHUDTd36wWhDAOrzzlfG9FOS5MeSM"/>
</appSettings>
<!-- <> <> <> Appsettings <> <> <> -->
<devExpress>

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace BeWo.Service.Core
{
public static class MergedConfig
{
public static string GetSetting(string key)
{
// 1. Versuche, aus AppSettings.local.config zu lesen
var localConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Web.Secrets.config");
if (File.Exists(localConfigPath))
{
var xml = new XmlDocument();
xml.Load(localConfigPath);
var node = xml.SelectSingleNode($"/appSettings/add[@key='{key}']");
if (node is XmlElement element)
return element.GetAttribute("value");
}
// 2. Fallback: Standard-AppSettings
return ConfigurationManager.AppSettings[key];
}
}
}

View File

@@ -230,6 +230,7 @@
<Compile Include="Core\DiamantExporter.cs" />
<Compile Include="Core\ExcelDownload.cs" />
<Compile Include="Core\FileAttachmentUtils.cs" />
<Compile Include="Core\MergedConfig.cs" />
<Compile Include="Core\ServiceLogic.cs" />
<Compile Include="Core\SettingsLogic.cs" />
<Compile Include="Core\Utils.cs" />

View File

@@ -110,7 +110,7 @@ namespace BeWo.Service.ServiceProxy
protected override string getKey()
{
var key = ConfigurationManager.AppSettings["OpenWebUIKey"];
var key = Core.MergedConfig.GetSetting("OpenWebUIKey");
if (string.IsNullOrEmpty(key))
throw new InvalidOperationException("OpenWebUIKey is missing");