15

I've got an azure webjob, that has some appsettings for api keys etc.

I've also got a bunch of PRODUCTION azure app settings (specified in the portal), that should override my webjob config appsettings.. But they don't.

For my website, they work as expected, and all is fine. For the webjobs however, they just get completely ignored, and my app settings from the config are used instead.

Is this a bug in azure? All the docs suggest that this should work.

EDIT

I found this blog all about using CloudConfigurationManager.GetSetting so I've implemented that and it still won't work - still using the settings that are defined in web job's app settings file :(

Thanks

Matt Roberts
  • 26,371
  • 31
  • 103
  • 180

7 Answers7

8

So it looks like I've found a bug!

It's because my AppSettings were referenced from another file, like this (in app.config):

<AppSettings file="appsettings.config"/>

This basically breaks azure's config management.

Matt Roberts
  • 26,371
  • 31
  • 103
  • 180
  • So, what is the solution here ? – Barbaros Alp Oct 12 '15 at 06:24
  • What was your reason for having them in a separate file? If you only need this in Dev/Debug, you could create a web config transform for Debug to use that separate file and then just leave that out of the transforms or don't have one, for the other environments – Dan Csharpster Oct 28 '16 at 15:32
  • 3
    Did you try using `configSource="appsettings.config"` instead? – Mike Goatly Jan 18 '17 at 11:38
  • Using `configSource="appsettings.config"` instead of `file="appsettings.config"` works. Information about the differences [here](https://stackoverflow.com/questions/6940004/asp-net-web-config-configsource-vs-file-attributes). Tested with Microsoft.Azure.WebJobs v2.2.0 today. – Drasive Apr 09 '20 at 13:42
1

Use

"D:\home\site\wwwroot\" to create an absolute path to files inside your website.

inside your WebJob to point to any file inside your wwwwroot directory. Using the Absolute path with D:\home\site\wwwroot\appsettings.config should fix you website.

C B
  • 1,964
  • 14
  • 13
1

Did you set your settings only in the Web.config file or did you set them in the portal or using the VS "Website Settings" tooling? You need to set the WebJobs-related settings at that level, not just in the Web.config. Once you do that, restart your site, and the settings should be there.

brady gaster
  • 1,506
  • 1
  • 10
  • 15
1

I had a similar problem but for me it was that we set the "is_in_place" settings.job value to true. I guess when it's in place, it doesn't update the config file with the settings. We didn't have a strict requirement that it run in place, so removing that setting fixed the problem for us.

Gave Drohl
  • 93
  • 2
  • 8
1

I have a similar problem with several web jobs sharing a common settings file. It would be inconvenient to duplicate the settings in each job.

Someone mentioned using configSource= instead of file= in the app.config to reference the external config settings file. I tried this, and it appears that it now works as expected. The settings are being taken from the Portal App Settings instead of the file now.

Fortunately, the settings for the web jobs all come from the external file. The use of file= allowed me to use additional per-app settings other than just those in the file, but fortunately I don't need to do that.

Hugh Martin
  • 86
  • 1
  • 2
0

A workaround to this problem is to place the settings inline in the AppSettings tag of the Web.config like this.

<AppSettings>
    <add key="host" value="someHost" />
</AppSettings>
CurtisJD
  • 46
  • 4
0

Azure App Service Application Settings are persisted in the Environment Variables. Go to the Azure Portal add your application settings or connection string values. Then, you can check out the environment variables of your app service at https://sitename.scm.azurewebsites.net

If you want your webjobs to share those settings, in your webjob project, create a appsettings.json:

{
  "APPSETTING_AzureWebJobsDashboard": "",
  "APPSETTING_AzureWebJobsStorage": "",
  "SQLAZURECONNSTR_xxx": ""
}

In your Main() method

private static void Main(string[] args)
{
            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                .AddEnvironmentVariables();

            var configurations = builder.Build();

            var services = new ServiceCollection()
                .AddDbContext<ApplicationDbContext>(options =>
                        options.UseSqlServer(configurations["SQLAZURECONNSTR_xxx"]),
                    ServiceLifetime.Transient)
                .BuildServiceProvider();

            var host = new JobHost(new JobHostConfiguration
            {
                DashboardConnectionString = configurations["APPSETTING_AzureWebJobsDashboard"],
                StorageConnectionString = configurations["APPSETTING_AzureWebJobsStorage"]
            });

            host.RunAndBlock();
        }

This is simpler than trying to figure out the path to the website config on the app service

cronixis
  • 368
  • 5
  • 9