.NET Core Azure WebJobs does not read from Azure Application Settings

天大地大妈咪最大 提交于 2019-12-12 11:00:49

问题


I have an app service running with it's respective ConnectionString from Azure Portal. The ConnectionString is point to Azure SQL Server.

I have a WebJob with the following appsettings.json

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

When I run the Web Job, it doesn't seem to pull the Connection strings from the azure portal, but it uses my default ConnectionStrings in appsettings.json.

[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:


Make sure you call AddEnvironmentVariables() when building your configuration. e.g.

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


来源:https://stackoverflow.com/questions/42200180/net-core-azure-webjobs-does-not-read-from-azure-application-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!