I tried referring the solution suggested on https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-3.1 with the section Set the environment.Also, I added the below part of code in Project file/publish profile
For Windows IIS deployments: Include the property in the publish profile (.pubxml) or project file. This approach sets the environment in web.config when the project is published:
<PropertyGroup>
<EnvironmentName>Development</EnvironmentName>
</PropertyGroup>
when I deploy the solution on host server which is PCF (pivotal cloud foundry). .Netcore runtime is always taking the hosting environment as "Production" instead of Development
If you want to use it as environment variable then would suggest to do this
Use below command to set the environment variable in PCF:
cf set-env ENV_RUN development
Read across the environment value in the application using -
Environment.GetEnvironmentVariable("ENV_RUN");