如何从App Settings Azure(webapp)到我的webjob接收数据 [英] How to receive data from App Settings Azure (webapp) to my webjob

查看:91
本文介绍了如何从App Settings Azure(webapp)到我的webjob接收数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用c#制作了Azure WebJob.我在Azure上有一个Web应用程序,我将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?

我会这样尝试,但无法正常工作,在这种情况下,不需要在我的Web配置中使用该密钥吗?当webjob运行时,需要从存储在Azure上的我的webapp的Appsettings中获取价值

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"];

推荐答案

在天蓝色的应用程序上运行时,如何在我的应用程序中获得密钥的价值?

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

根据我的测试,如果我们在azure门户上没有设置,我们将在Webjob中获得空值.请在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.

完成此操作后,以下所有方法均应工作

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");

这篇关于如何从App Settings Azure(webapp)到我的webjob接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆