The Startup class contains
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();
}
but env.EnvironmentName.ToString() returns "Production".
I already setup my ASPNETCORE_ENVIRONMENT to "Development" in launchSettings.json
This usually happens when you have setup environment in web.config
too.
For example, if you have environment setup as Production
in launchSettings.json
-
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
},
And in web.config
, if you have other environment Staging
-
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Staging" />
</environmentVariables>
</aspNetCore>
In this case, you will get Staging
when you are trying to read env.EnvironmentName
in startup.cs
See if this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With