Setting ASPNETCORE_ENVIRONMENT variables system wide for BLUE GREEN setup

Lance Lyons 86 Reputation points
2023-04-18T20:32:38.25+00:00

Hi,

we have a number of environments (CI, QA, STAGING, BLUE, GREEN) where we have set the ASPNETCORE_ENVIRONMENT variable for the entire environment at the machine level.

this is set in the applicationHost.config in the system.webServer area as shown below.

        <aspNetCore>
            <environmentVariables>
                <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="DEV" />
                <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="DEV" lockItem="true" />
            </environmentVariables>
        </aspNetCore>

However in our BLUE GREEN environments, a set of webservers might be for TEST and then another is PRODUCTION and vice versa.

I know we can do this in the web.configs for each app but was hoping we can do this machine wide like we did above.

is there a way to set these values programatically for the entire webserver? Thanks in advance

 
            <environmentVariables>
                <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="RC" />
                <envi
Internet Information Services
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,553 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. AgaveJoe 28,366 Reputation points
    2023-04-18T22:04:46.99+00:00

    I use the system variables on the Windows server.
    Windows - Set environment variable globally See the official documentation for all the different ways to handle configuration in ASP.NET Core. Configuration in ASP.NET Core

    0 comments No comments

  2. TengFeiXie-MSFT 346 Reputation points
    2023-04-19T07:58:53.0866667+00:00

    Hi, @Lance Lyons

    To set the value globally in Windows, use either of the following approaches: Open the Control Panel > System > Advanced system settings and add or edit the ASPNETCORE_ENVIRONMENT value:System Advanced Properties

    ASPNET Core Environment Variable

    Of course, you can also set environment variables in the applicationhost.config of IIS, which will take effect on the application you deploy in IIS. Just like this link, But sometimes it still need to set it in web.config.

    Best Regard,

    TengFei Xie


    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. jacqueline callaghan 0 Reputation points
    2024-03-17T09:57:16.2966667+00:00

    How do I delete this

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.