问题
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