2

I have webapp in azure and with that webapp i have 3 other webjobs inside that. now Webapp is having some settings in appConfig section in web.config. I don't want to copy and past that settings in my other 3 webjob. so is it possible to read Web.config of webApp from Webjob ?

Mahesh
  • 730
  • 7
  • 26
  • did you have a look at CloudConfigurationManager ? https://www.nuget.org/packages/Microsoft.WindowsAzure.ConfigurationManager/ – Thomas Jan 22 '16 at 09:19
  • ya i know about that but i guess that doesn't solve my problem – Mahesh Jan 22 '16 at 09:23
  • So is it specific to azure web app and webjob ? Look at this post: http://stackoverflow.com/questions/27691636/write-appsettings-in-external-file, it will explain you how to externalize your app settings. – Thomas Jan 22 '16 at 09:27

2 Answers2

5

You can share the settings between your Web App and your WebJobs by storing them in the Web App's app settings (on the Azure portal).

To access these settings you simply use ConfigurationManager.AppSettings or if it's not .NET you can access them through the environment (as environment settings).

Amit Apple
  • 9,034
  • 41
  • 50
  • Getting Application Settings as Environment Settings worked for me. For such please refer [this](https://azure.microsoft.com/en-us/blog/windows-azure-web-sites-how-application-strings-and-connection-strings-work/) Do mind of the Prefixes! :) – hiFI Aug 23 '17 at 08:12
0

If you add the nuget package Microsoft.Extensions.Configuration.EnvironmentVariables then you can use the extension method .AddEnvironmentVariables() on your ConfigurationBuilder. This then means that any data in environment variables will be picked up by your config.

The settings you configure in Azure portal's Your Web App / Configuration are put to environment variables and become available to your webjob

Configure settings in here: enter image description here

Have a code in your console app like:

_config = new ConfigurationBuilder()
            .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
            .AddJsonFile("appsettings.json")
            .AddUserSecrets<Program>()
            .AddEnvironmentVariables()
            .Build();

var someSetting = _config["some"];

When you configure a setting called some in the azure portal, it will appear in your code thanks to it being placed in an environment variable and the config reading it out of that place