.NET Core Azure WebJobs无法从Azure应用程序设置中读取

时间:2017-02-13 09:01:39

标签: .net azure .net-core azure-webjobs webjob

我有一个应用服务,它运行着来自Azure门户的相应ConnectionString。 ConnectionString指向Azure SQL Server。 Azure Portal Application Settings for Connection String

我有一个带有以下appsettings.json的WebJob

{
  "ConnectionStrings": {
    "DefaultConnection": "Add your connection string"
  }
}

当我运行Web作业时,它似乎不会从天蓝色门户中提取连接字符串,但它在appsettings.json中使用我的默认ConnectionStrings。

[02/13/2017 08:45:27 > 2942c6: SYS INFO] Status changed to Initializing
[02/13/2017 08:45:27 > 2942c6: SYS INFO] Run script 'run.cmd' with script host - 'WindowsScriptHost'
[02/13/2017 08:45:27 > 2942c6: SYS INFO] Status changed to Running
[02/13/2017 08:45:27 > 2942c6: INFO] 
[02/13/2017 08:45:27 > 2942c6: INFO] D:\local\Temp\jobs\triggered\TestConnectionString\32vmiek4.2av>dotnet TestConnectionString.dll 
[02/13/2017 08:45:29 > 2942c6: INFO] Add your connection string

1 个答案:

答案 0 :(得分:6)

确保在构建配置时致电AddEnvironmentVariables()。 e.g。

var builder = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json")
    .AddEnvironmentVariables();