本文介绍了.NET Core Azure WebJobs 不从 Azure 应用程序设置读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序服务,它在 Azure 门户中使用相应的 ConnectionString 运行.ConnectionString 指向 Azure SQL Server.

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

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

I have a WebJob with the following appsettings.json

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

当我运行 Web 作业时,它似乎没有从 azure 门户中提取连接字符串,但它使用我在 appsettings.json 中的默认连接字符串.

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:localTempjobs	riggeredTestConnectionString32vmiek4.2av>dotnet TestConnectionString.dll
[02/13/2017 08:45:29 > 2942c6: INFO] Add your connection string

推荐答案

确保在构建配置时调用 AddEnvironmentVariables().例如

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

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

这篇关于.NET Core Azure WebJobs 不从 Azure 应用程序设置读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 19:29