0
votes

I have an asp.net core application which has settings for the Identity Server. For that I have have a appsettings.json, an appsettings.Development.json and an appsettings.Production.json.

appsettings.json:

..
  "ApplicationInsights": {
    "InstrumentationKey": ""
  },
  "IdentityServer": {
    "Clients": {
      "ApplySupportTool.Client": {
        "Profile": "IdentityServerSPA"
      }
    }
  },
  "BuildInfo": {
    "Environment": "Integration",
    "Version": "1.0.0 Beta"
  },
..

appsettings.Development.json

{
  "IdentityServer": {
    "Key": {
      "Type": "Development"
    }
  }
}

appsettings.Production.json

{
  "IdentityServer": {
    "Key": {
      "Type": "Store",
      "StoreName": "My",
      "StoreLocation": "CurrentUser",
      "Name": "[Name]"
    }
  }
}

Locally that works without a problem, and I can switch between them with removing the environment variable from the launchsettings:

    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development"
    }

In Terms of loading the settings files analog to the default template my HostBuilder is created like this with no special additions for the settings files.

    public static IHostBuilder CreateHostBuilder(string[] args)
    {
        return Host.CreateDefaultBuilder(args)
                   .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                   .ConfigureWebHostDefaults(webHostBuilder =>
                   {
                       webHostBuilder
                          .UseContentRoot(Directory.GetCurrentDirectory())
                          .UseStartup<Startup>()
                          .UseAzureAppServices();
                   })
                   .UseSerilog();
    }

When I check in the constructor of the Startup.cs I can verify that it loaded the additional file as well.

But when I deploy that to Azure it seems that always the development version is loaded. As far as I know with no value set it should go for production (which works local). To be sure I also tried to add a ASPNETCORE_ENVIRONMENT with the value "Production" to my AppService explicitly. But that didn't change anything too. Do I have to load that in a special way or something?

1
I was wrong with this issue. The Settings are read correctly. My problem lies somewhere else.NPadrutt

1 Answers

0
votes

Hope Development is not kept last in Program.cs which overrides your appsetting and production.json

var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
        .AddEnvironmentVariables();

Also in WebAPP blade if you are overriding the ASPNETCORE_ENVIRONMENT variable need to restart the instance to reflect and reload the changes.

Also more information interms of your program.cs will helps us to find the root cause.