ASP.NET Core hosting environment variable ignored

Thaoden

I have two web sites on my staging server, and both are ASP.NET Core sites that run in IIS. I have set the environment variable ASPNETCORE_ENVIRONMENT to Staging machine-wide. This works well for one of the sites, however the other ignores the variable and runs in production mode instead. I have to configure the hosting environment into the web.config file to run it in staging mode.

Why does one site not take the environment variable into account?

In both of my Startup(IHostingEnvironment env) constructors, I use the environment variables:

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)
        .AddJsonFile("logging.json")
        .AddEnvironmentVariables();  //   <---
        Configuration = builder.Build();
    }
Thaoden

As said in this similar question, the trick was simply to set the app pool to load the user variables (IIS -> Server -> App Pools -> Right click on pool -> Set application pool defaults... -> Load User Profile = True).

I configured only one of my app pools accordingly, thus only one of the sites could access the environment variables.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Is it possible to determine the ASP.NET Core hosting environment in an HTML helper method?

分類Dev

VSTS/TFS set environment variable ASP.NET core

分類Dev

ASP.NET Core hosting - 500 internal server error

分類Dev

ASP.Net Core Data Protection API in a Clustered Environment

分類Dev

Angular - Multiple environment with asp.net core spa

分類Dev

Hosting multiple product APIs in single ASP.NET Core WebAPI Service

分類Dev

ASP.NET Core:hosting.jsonのURLが読み込まれていません

分類Dev

How to correctly store connection strings in environment variables for retrieval by production ASP.Net Core MVC applications

分類Dev

.NET CoreとASP.NET Core

分類Dev

Publishing and hosting Web API developed in .net core through IIS

分類Dev

Hosting Web API in .Net Core Worker Service - cannot reference IWebHostEnvironment

分類Dev

Hosting ASP.NET in IIS7 gives Access is denied?

分類Dev

ASP.Net Core 2.1ASPNETCORE_ENVIRONMENT値が反映されていない

分類Dev

ASP.Net Core 2.1ASPNETCORE_ENVIRONMENT値が反映されていない

分類Dev

ASP.NET Core ToHtmlString

分類Dev

Cookieless ASP.NET Core

分類Dev

How to set ASP.NET 5 environment variables on production environment

分類Dev

.Net Core2.xでのMicrosoft.AspNetCore.Hosting.WindowsServicesの使用

分類Dev

Getting Microsoft.AspNetCore.Hosting.Diagnostics[6] Application startup exception in .NET Core 3

分類Dev

ASP.Net Core SAML authentication

分類Dev

ASP.Net Core SAML authentication

分類Dev

ASP.Net Core SAML authentication

分類Dev

ASP.NET CORE 2.0のFromUri

分類Dev

ASP.NET Core 2.0 authentication middleware

分類Dev

ASP.NET CoreのPayPal

分類Dev

How to enable CORS in ASP.NET Core

分類Dev

ASP .Net Core Routingの問題?

分類Dev

Path to LocalAppData in ASP.Net Core application

分類Dev

ASP.NET Core 1.0SynchronizationContext

Related 関連記事

  1. 1

    Is it possible to determine the ASP.NET Core hosting environment in an HTML helper method?

  2. 2

    VSTS/TFS set environment variable ASP.NET core

  3. 3

    ASP.NET Core hosting - 500 internal server error

  4. 4

    ASP.Net Core Data Protection API in a Clustered Environment

  5. 5

    Angular - Multiple environment with asp.net core spa

  6. 6

    Hosting multiple product APIs in single ASP.NET Core WebAPI Service

  7. 7

    ASP.NET Core:hosting.jsonのURLが読み込まれていません

  8. 8

    How to correctly store connection strings in environment variables for retrieval by production ASP.Net Core MVC applications

  9. 9

    .NET CoreとASP.NET Core

  10. 10

    Publishing and hosting Web API developed in .net core through IIS

  11. 11

    Hosting Web API in .Net Core Worker Service - cannot reference IWebHostEnvironment

  12. 12

    Hosting ASP.NET in IIS7 gives Access is denied?

  13. 13

    ASP.Net Core 2.1ASPNETCORE_ENVIRONMENT値が反映されていない

  14. 14

    ASP.Net Core 2.1ASPNETCORE_ENVIRONMENT値が反映されていない

  15. 15

    ASP.NET Core ToHtmlString

  16. 16

    Cookieless ASP.NET Core

  17. 17

    How to set ASP.NET 5 environment variables on production environment

  18. 18

    .Net Core2.xでのMicrosoft.AspNetCore.Hosting.WindowsServicesの使用

  19. 19

    Getting Microsoft.AspNetCore.Hosting.Diagnostics[6] Application startup exception in .NET Core 3

  20. 20

    ASP.Net Core SAML authentication

  21. 21

    ASP.Net Core SAML authentication

  22. 22

    ASP.Net Core SAML authentication

  23. 23

    ASP.NET CORE 2.0のFromUri

  24. 24

    ASP.NET Core 2.0 authentication middleware

  25. 25

    ASP.NET CoreのPayPal

  26. 26

    How to enable CORS in ASP.NET Core

  27. 27

    ASP .Net Core Routingの問題?

  28. 28

    Path to LocalAppData in ASP.Net Core application

  29. 29

    ASP.NET Core 1.0SynchronizationContext

ホットタグ

アーカイブ