2

I have ASP.Net Core 2.1 API app. It is supposed to host in 4 environments.

  1. Development
  2. Testing
  3. Staging
  4. Production

When running the app in local from Visual Studio, the app is rightly fetching the ASPNETCORE_ENVIRONMENT variable & accordingly fetching the values from appsettings.Development.json

Local Dev Machine

But when the same deployed in a VM, it's not fetching the environment & looking for settings (like Connection string etc.) from appsettings.json.

Test Environment

What else settings I need to do so?

Thanks!

7
  • 2
    Check this out. learn.microsoft.com/en-us/aspnet/core/fundamentals/… Commented Sep 12, 2019 at 13:03
  • @cleftheris Thanks! as per the above link I added the below settings in launchsettings.json jsoneditoronline.org/?id=da032fc0d3ef4fc9a1d75bc88b1f7c18 Commented Sep 12, 2019 at 13:41
  • @cleftheris but when added, its throwing runtime error 500 - The requested address is not valid in its context Commented Sep 12, 2019 at 13:41
  • 1
    launchSettings.json is only used by dotnet run ( i.e. inside Visual Studio), it's more than useless for deployment to IIS. Commented Sep 12, 2019 at 15:50
  • @Kgn-web You should check the section called "set-the-environment" in the documentation above. Assuming you are running on windows according to the docs you can either. A. Set a windows global environment variable through the system settings. B. Set the environment variable through web.config. The B option is easier. Commented Sep 13, 2019 at 6:33

1 Answer 1

3

You should be setting System Environment Variable rather than User Variable.

Sign up to request clarification or add additional context in comments.

2 Comments

As more context, you're adding the environment variable for your user profile, i.e. the one you're logged into the machine as. That is almost certainly not the same user that the App Pool in IIS is running as. As such, it has no access to any environment variables set on your user profile. You can add a user variable, but it has to be done on the user that the App Pool is running as. Otherwise, a system variable will be accessible to all users.
@ChrisPratt, can you please check the error mentioned in the comments? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.