0

I have an API hosted in IIS.

In local testing, with very scenario, it works perfectly. When deployed to IIS, the appsettings.uat1.json did not get loaded and some environment variables are not changed.

var environment = builder.Configuration.GetSection("Environment").Get<string>();

_logger.Info($"Environment set to: {environment}");

builder.Configuration.SetBasePath(Directory.GetCurrentDirectory())
                     .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                     .AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
                     .AddEnvironmentVariables();

_logger.Info($"Client group environment set to: {builder.Configuration.GetSection("Client:GroupEnviroment").Get<string>()}");

In the log file from IIS I can see the following:

Environment set to: uat1
Client group environment set to: dev6

Now the dev6 value is coming from appsettings.json and the uat1 is coming from appsettings.uat1.json.

I can't figure it out why is that in local testing, I can see that the appsettings.uat1.json is loaded, and the configuration has the right value, but when deployed to IIS, the appsettings.env.json is not loaded, the values for the key are not replaced with redefined in the env json file.

Thanks

5
  • 2
    First, you have to confirm that your appsettings.uat1.json is deployed to the correct location alongside your main appsettings.json. Typically, it should be in the same directory as your main configuration file (appsettings.json). Commented Jul 17, 2024 at 10:00
  • We just found out from logs, that the file does not exist on, but in the deployment process we can see that it is contained in the zip file Commented Jul 17, 2024 at 11:12
  • The file is searched at C:\Windows\system32\appsettings.uat1.json location, but I know that the file is somewhere in the drive E Commented Jul 17, 2024 at 11:42
  • I think you might have an issue how to get the project directory, try a different base path stackoverflow.com/questions/43709657/… Commented Jul 17, 2024 at 14:23
  • The behavior shows that the configuration files set default to C:\Wnidows\system32 and Directory.GetCurrentDirectory() won't work, which makes file not found. Try builder.Environment.ContentRootPath to get the correct path. Commented Jul 18, 2024 at 6:20

0

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.