Azure WebJobs从何处读取配置设置?
我正在使用Visual Studio 2019和Microsoft.NETCore.App v5.0.0框架开发Azure WebJob。我需要从配置中读取值,但我不知道应该将它们放在哪里,以便最终在Azure门户中的Azure WebJob页面中覆盖它们。到目前为止,我已经创建了以下Azure WebJobs从何处读取配置设置?,azure,configuration-files,azure-webjobs,appsettings,azure-webjobssdk,Azure,Configuration Files,Azure Webjobs,Appsettings,Azure Webjobssdk,我正在使用Visual Studio 2019和Microsoft.NETCore.App v5.0.0框架开发Azure WebJob。我需要从配置中读取值,但我不知道应该将它们放在哪里,以便最终在Azure门户中的Azure WebJob页面中覆盖它们。到目前为止,我已经创建了以下appsettings.json: { "ConnectionStrings": { "AzureWebJobsStorage": "..."
appsettings.json
:
{
"ConnectionStrings": {
"AzureWebJobsStorage": "..."
},
"firstValue": "...",
"secondValue": "..."
}
下面的公共方法
public static async Task Example(
[BlobTrigger("%firstValue%/{blobName}")] Stream blobReceived
[Blob("%secondValue%/{blobName}", FileAccess.Write)] Stream blobToWrite,
ILogger logger)
从appsettings.json
正确读取firstValue
和secondValue
的值。也就是说,我看到了其他使用app.config
文件的项目,这些文件的值随后通过以下方式检索:
ConfigurationManager.AppSettings["..."];
ConfigurationManager.ConnectionStrings["..."].ConnectionString;
我应该使用
app.config
而不是appsettings.json
?当我们谈到Azure WebJobs时,如何读取我在<代码> AppStase.JSON<代码>文件中的值?< /P> < P> <强>您不能直接访问Azure WebJobs的应用程序设置>,但您可以考虑使用REST API访问Azure门户中的AppSt设置。
实际上,WebJobs是控制台应用程序,它使用存储在系统中的环境变量,这与Azure门户中的AppSettings不同。IIS中存储的应用设置只能从此特定web应用调用。app.config(如果适用于.net framework应用)。appsettings适用于.net核心应用。@ThiagoCustodio谢谢。如何从
appsettings.json
读取值?如您所见,firstValue
和secondValue
是使用%…%
语法读取的,因为据我所知,这是属性的特殊语法。