Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to receive data from App Settings Azure (webapp) to my webjob

I have made an Azure WebJob in c#. I have a web app on Azure, I added my WebJob to my subscription, all good works but in Application Settings I add a new entry, an example:

<add key="MyDesiredKey" value="1234" /> 

How can I get value of my key into my application when that runs on azure?

I try like this but not working, in this case no need to have that key in my web config no? When webjob run need to get value from Appsettings from my webapp stored on Azure

var keyFromAzureApp = ConfigurationManager.AppSettings["MyDesiredKey"];
like image 331
Ciprian Jijie Avatar asked Dec 07 '22 17:12

Ciprian Jijie


1 Answers

How can I get value of my key into my application when that runs on azure?

According to my test if we have no setting on the azure portal, we will get the null value in the Webjob. Please add it on the azure portal, more detail please refer to the screenshot.

enter image description here

After doing that then all of following ways should work

 var myDesiredKey = ConfigurationManager.AppSettings["MyDesiredKey"];
 var environmentmyDesiredKey  = Environment.GetEnvironmentVariable("MyDesiredKey");
 var cloudmyDesiredKey = CloudConfigurationManager.GetSetting("MyDesiredKey");
like image 141
Tom Sun - MSFT Avatar answered May 18 '23 23:05

Tom Sun - MSFT