哪种方式从 local.settings.json .NET6 获取值?
有人可以解释一下哪种方式(如果有的话)是从 local.settings.json、C# .NET6 中获取 Startup 类中的值的首选方式。 startup.cs 用于一个函数。
client.BaseAddress = new Uri(configuration["BaseEndpoints:RestIg"]);
client.BaseAddress = new Uri(Environment.GetEnvironmentVariable("BaseEndpoints:RestIg"));
client BaseAddress = new Uri(configuration.GetSection("BaseEndpoints:RestIg").Value);
在我的 local.settings.json 中,我可以将 BaseEndpoints:RestIg 的值设置在 value{} 内部或外部,但不确定我想将其放置在哪里?
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"TimerInterval": "0 0 * * * *"
},
"BaseEndpoints": {
"RestIg": "https://myurl.com....etc.etc.etc"
}
}
Could someone please explain which way, if any of these, is the preferred way of fetching values in Startup class from local.settings.json, C# .NET6. The startup.cs is for a function.
client.BaseAddress = new Uri(configuration["BaseEndpoints:RestIg"]);
client.BaseAddress = new Uri(Environment.GetEnvironmentVariable("BaseEndpoints:RestIg"));
client BaseAddress = new Uri(configuration.GetSection("BaseEndpoints:RestIg").Value);
In my local.settings.json I can have the value of BaseEndpoints:RestIg either inside or outside the values{}, not sure where I would want to place it?
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"TimerInterval": "0 0 * * * *"
},
"BaseEndpoints": {
"RestIg": "https://myurl.com....etc.etc.etc"
}
}
According to this dude Microsoft recommends this method because it works both locally with local.settings.json and in Azure.
i.e.Environment.GetEnvironmentVariable("BaseEndpoints:RestIg");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论