c# - Azure Functions - 当我尝试本地调试时,配置设置返回 null

标签 c# azure azure-functions configurationmanager

我有以下代码:

    [FunctionName("FunctionValidateDriverRecord")]
    public static async Task Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, TraceWriter log)
    {
        string connString = ConfigurationManager.ConnectionStrings["AssetContext"].ConnectionString;
        string mail = ConfigurationManager.AppSettings["EmailForErrors"];

和 local.settings.json:

{
  "IsEncrypted": false,
  "ConnectionStrings": {
    "AssetContext": "data source=server;initial catalog=3md_vistracks_sync;integrated security=True;MultipleActiveResultSets=True"
  },
  "AppSettings": {
    "EmailForErrors": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="72100013071c111d1f1f32151f131b1e5c111d1f" rel="noreferrer noopener nofollow">[email protected]</a>"
  }
}

connString 有值,但 mail 为空。为什么?

最佳答案

在 local.settings.json 中,您应该使用 Values 而不是 AppSettings。 Azure 函数本地开发需要文件架构。

您可能正在使用 v1 函数,请随意使用 ConfigurationManager,因为您发现它对 connectionString 有效。 v2不支持ConfigurationManager,可以引用环境变量,看这个answer有关读取本地和 Azure 设置的更多详细信息。

关于c# - Azure Functions - 当我尝试本地调试时,配置设置返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51823948/

相关文章:

c# - 使服务器端字符串在客户端脚本中安全使用

c# - 返回自定义结果的单元测试 ASP.NET Web API 2 Controller

azure - ARM模板部署的功能应用程序没有主机 key 并引发错误

azure - “az functionapp 部署”报告成功,但 Azure 中的函数 View 为空

azure - Azure 中的 ConnectionString 不会覆盖 Azure Function 的 LocalSqlServer

c# - 碰撞时播放随机声音片段 (Unity)

C#类函数成员声明与实现

Azure Powershell 新-AzADUser : A parameter cannot be found that matches parameter name 'MobilePhone'

ios - 自定义 API 移动服务 Azure IOS

python - 无法在Python中使用azure SDK