1

I have a Core WebJob deployed into an Azure Web App. I'm using WebJobs version 3.0.6.

I've noticed that changes to Connection Strings and App Settings (added via the Azure web UI) are not being picked up immediately by the WebJob code.

This seems to correlate with the same Connection Strings and App Settings not being displayed on the app's KUDU env page straight away (although I acknowledge this may be a red herring and could be some KUDU caching thing which I'm unaware of).

I've deployed a few non-Core WebJobs in the past and have not come across this issue so wonder if it's Core related? Although I can't see how that might affect configs showing up KUDU though.

I was having this issue the other day (where the configs were not getting picked up by the WebJob or shown in KUDU) and was getting nowhere, so left it. When I checked back the following day, the configs were now correctly showing in KUDU and being picked up by the WebJob. So I'd like to know what has happened in the meantime which means the configs are now being picked up as expected.

I've tried re-starting the WebJob and re-starting the app after making config changes but neither seem to have an effect.

It's worth also noting that I'm not loading appSettings.json during the program setup. That being said, the connection string being loaded was consistenly the connection string from that file i.e. my local machine SQL Server/DB. My understanding was always that the anything in the Azure web UI would override any equivalent settings from config files. This post from David Ebbo indicates that by calling AddEnvironmentVariables() during the setup will cause the Azure configs to be observed, but that doesn't seem to be the case here. Has this changed or is it loading the configs from this file by convention because it can't see the stuff from Azure?

Here's my WebJob Program code:

    public static void Main(string[] args)
    {
      var host = new HostBuilder()
      .ConfigureHostConfiguration(config =>
      {
        config.AddEnvironmentVariables();
      })
      .ConfigureWebJobs(webJobConfiguration =>
        {
          webJobConfiguration.AddTimers();
          webJobConfiguration.AddAzureStorageCoreServices();
        }
      )
      .ConfigureServices((context, services) =>
      {
        var connectionString = context.Configuration.GetConnectionString("MyConnectionStringKey");

        services.AddDbContext<DatabaseContext>(options =>
          options
            .UseLazyLoadingProxies()
            .UseSqlServer(connectionString)
        );

        // Add other services
      })
      .Build();

      using(host)
      {
        host.Run();
      }
    }

So my questions are:

  • How quickly should configs added/updated via the Azure web UI be displayed in KUDU?
  • Is the fact they're not showing in KUDU related to my Core WebJob also not seeing the updated configs?
  • Is appSettings.json getting loaded even though I'm not calling .AddJsonFile("appSettings.json")?
  • What can I do to force the new configs added via Azure to be available to my WebJob immediately?
lee_mcmullen
  • 2,801
  • 32
  • 39

1 Answers1

0

The order in which configuration sources are specified is important, as this establishes the precedence with which settings will be applied if they exist in multiple locations. In the example below, if the same setting exists in both appsettings.json and in an environment variable, the setting from the environment variable will be the one that is used. The last configuration source specified “wins” if a setting exists in more than one location. The ASP.NET team recommends specifying environment variables last, so that the environment where your app is running can override anything set in deployed configuration files.

You can refer here for more details on Azure App Services Application Settings and Connection Strings in ASP.NET Core

  • Thanks. Yes that was my understanding too. However as stated in my question, the issue seems to be that the settings are not getting picked up right away. Also I'm deliberately not configuring `appSettings.json` (see my code sample) as I don't want it used (I want all settings configured in the web app), yet my web app settings are not being used and it still seems to be using `appSettings.json`. – lee_mcmullen Apr 24 '19 at 13:12
  • Apologies for the delay. To add further, the call to add the variables is actually handled by the SDK as well. I’m suspecting an issue with the way the connection string is setup in App Service. Can you let me know which type/provider is being used? Could you share with us your site name or subscription ID indirectly as explained here https://github.com/projectkudu/kudu/wiki/Reporting-your-site-name-without-posting-it-publicly? We can check the configuration to ensure things are properly setup. Also, is the app published via the VS right-click tooling? – DashleenBhandari-MSFT May 04 '19 at 15:05