gpt4 book ai didi

c# - Startup.cs 返回错误的环境

转载 作者:太空狗 更新时间:2023-10-29 23:36:56 26 4
gpt4 key购买 nike

Startup类包含

public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

Console.WriteLine($"{env.EnvironmentName.ToString()}");

if (env.IsDevelopment())
{
// For more details on using the user secret store see
// https://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}

builder.AddEnvironmentVariables();
Configuration = builder.Build();
}

但是 env.EnvironmentName.ToString() 返回“Production”。

我已经在 launchSettings.json 中将我的 ASPNETCORE_ENVIRONMENT 设置为“开发”

最佳答案

当您也在 web.config 中设置环境时,通常会发生这种情况。

例如,如果您在 launchSettings.json 中将环境设置为 Production-

  "profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
},

并且在web.config中,如果你有其他环境Staging-

<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Staging" />
</environmentVariables>
</aspNetCore>

在这种情况下,当您尝试读取 startup.cs 中的 env.EnvironmentName 时,您将获得 Staging

看看这是否有帮助。

关于c# - Startup.cs 返回错误的环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39944489/

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