gpt4 book ai didi

c# - 如何列出 ASP.NET Core 中的所有配置源或属性?

转载 作者:行者123 更新时间:2023-12-04 11:12:14 26 4
gpt4 key购买 nike

我想确保正在从配置源读取特定的配置属性。我打算打印出所有配置源(或打印出所有配置属性),但我似乎无法弄清楚如何做到这一点。

这能做到吗?

最佳答案

从 .NET Core 3.0+ 你可以转换你的 IConfigurationIConfigurationRoot并使用 GetDebugView扩展方法。这将生成一个人类可读的配置 View ,显示每个值的来源。例如。

var root = (IConfigurationRoot)Configuration;
var debugView = root.GetDebugView();
样本输出到 debugView :
applicationName=Project.Name (Microsoft.Extensions.Configuration.ChainedConfigurationProvider)
ASPNETCORE_ENVIRONMENT=Development (EnvironmentVariablesConfigurationProvider)
ASPNETCORE_HTTPS_PORT=32774 (EnvironmentVariablesConfigurationProvider)
ASPNETCORE_LOGGING:
CONSOLE:
DISABLECOLORS=true (EnvironmentVariablesConfigurationProvider)
ASPNETCORE_URLS=https://+:443;http://+:80 (EnvironmentVariablesConfigurationProvider)
DOTNET_RUNNING_IN_CONTAINER=true (EnvironmentVariablesConfigurationProvider)
DOTNET_USE_POLLING_FILE_WATCHER=1 (EnvironmentVariablesConfigurationProvider)
AllowedHosts=* (JsonConfigurationProvider for 'appsettings.json' (Required))
Kestrel:
Certificates:
Development:
Password=xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxx (JsonConfigurationProvider for 'secrets.json' (Optional))
EmailOptions:
EnableSsl=False (JsonConfigurationProvider for 'appsettings.json' (Required))
ENVIRONMENT=Development (Microsoft.Extensions.Configuration.ChainedConfigurationProvider)
HOME=/root (EnvironmentVariablesConfigurationProvider)
HOSTNAME=2cb0f5c24cc0 (EnvironmentVariablesConfigurationProvider)
HTTPS_PORT=32774 (Microsoft.Extensions.Configuration.ChainedConfigurationProvider)
NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages;/root/.nuget/fallbackpackages2 (EnvironmentVariablesConfigurationProvider)
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin (EnvironmentVariablesConfigurationProvider)
PWD=/app (EnvironmentVariablesConfigurationProvider)
RUNNING_IN_CONTAINER=true (Microsoft.Extensions.Configuration.ChainedConfigurationProvider)
URLS=https://+:443;http://+:80 (Microsoft.Extensions.Configuration.ChainedConfigurationProvider)
USE_POLLING_FILE_WATCHER=1 (Microsoft.Extensions.Configuration.ChainedConfigurationProvider)

关于c# - 如何列出 ASP.NET Core 中的所有配置源或属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37688027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com