Har*_*wal 11 appsettings azure azure-functions
向其添加密钥的标准结构是什么appsettings.json
?另外,如何读取我们的那些值run.csx
?通常在app.config中,我们ConfigurationManager.GetSettings["SettingName"];
在Azure Function中是否有任何类似的实现?
Stu*_*tLC 12
在Azure Functions 2.x中,您需要使用包中包含的.Net核心配置管理样式Microsoft.Extensions.Configuration
。这使您可以settings.json
在开发计算机上创建本地文件,以便在json文件的Values
和ConnectionString
部分中进行本地配置。在local json
设置文件未发布天青,相反,天青将获得与功能相关联的应用程序设置的设置。
在功能代码中,接受type类型的参数,Microsoft.Azure.WebJobs.ExecutionContext context
然后可以在其中构建IConfigurationRoot
提供程序:
[FunctionName("MyFunction")]
public static async Task Run([TimerTrigger("0 */15 * * * *")]TimerInfo myTimer,
TraceWriter log, Microsoft.Azure.WebJobs.ExecutionContext context,
CancellationToken ctx)
{
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
// This abstracts away the .json and app settings duality
var myValue = config["MyKey"];
var myConnString = config.GetConnectionString("connString");
... etc
Run Code Online (Sandbox Code Playgroud)
将AddJsonFile
允许你添加一个地方发展配置文件如local.settings.json
包含本地开发值(不公开)
{
"IsEncrypted": false,
"Values": {
"MyKey": "MyValue",
...
},
"ConnectionStrings": {
"connString": "...."
}
Run Code Online (Sandbox Code Playgroud)
尽管似乎不鼓励将ConnectionStrings用于除EF之外的任何其他功能
部署到Azure后,您可以在功能应用程序设置刀片上更改设置的值:
归档时间: |
|
查看次数: |
20293 次 |
最近记录: |