bitshift
bitshift

Reputation: 6852

Appsettings.json How does one check to see what environment is being used?

If one has a running .net core web app and there are multiple appsettings.json files in the root, how can you tell what environmentname is set to? I guess one way is to write your own utility or status page where you use code to write out the value of this variable. Is there another way?

Instead of using some sort of transform as in the case with web.config files, you now generally deploy all the environment-specific appsettings files, and let the app determine the value of the environment. This seems kinda confusing, in that you no longer can simply look at a config file and know what settings the app is using.

Upvotes: 1

Views: 2892

Answers (1)

Andy
Andy

Reputation: 30418

You can check the value of IHostingEnvironment.Environment as William suggested in the comments, but a better approach would be to call either IHostingEnvironment.IsDevelopment() or IHostingEnvironment.IsEnvironment() and it will do the name checking for you.

Methods for checking for production (IHostingEnvironment.IsProduction()) and staging (IHostingEnvirionment.IsStaging()) exist as well.

Upvotes: 1

Related Questions