【发布时间】:2020-06-03 18:25:42
【问题描述】:
我正在 .net 核心 web api 上进行 dotnet 发布,它生成了一个 web.config,如下所示。这对开发人员来说很好,因为 RayGunKey 是正确的值,但是当我将它放在临时环境中时,它仍然具有“SOME-KEY-HERE”值!即使我在 staging web api 的 Configuration -> Application Settings 下创建了 RayGunKey(具有不同的值)。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MyApi.dll" stdoutLogEnabled="false" hostingModel="InProcess" stdoutLogFile=".\logs\stdout">
<environmentVariables>
<environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44392" />
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
<environmentVariable name="RayGunKey" value="SOME-KEY-HERE" />
<environmentVariable name="COMPLUS_ForceENC" value="1" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
我没有配置好启动文件吗?我怎样才能让它拉出暂存 RagGunKey 而不是使用在发布命令中创建的那个?
我目前正在使用以下代码,它似乎确实从 web.config 中提取了值,但正如我所说,我想从 azure 应用程序设置(环境变量)中提取它
var rayGunKey = Environment.GetEnvironmentVariable("RayGunKey");
我经常对环境变量感到困惑,尤其是在这种情况下。直接在 azure 和其他地方调用环境变量中的应用程序设置是不直观的!
在此先感谢
【问题讨论】:
标签: azure asp.net-core environment-variables