Dnx (asp.net 5) 找不到作为 Azure Web 作业连接字符串配置的控制台应用程序

Dnx (asp.net 5) Console app as Azure Web Job connection strings configuration not found

在所有关于如何为 Azure Web 作业获取存储连接的手册中,据说连接字符串中有这两个变量 AzureWebJobsDashboard、AzureWebJobsStorage。它适用于普通的 .net,但它对 DNX 来说是一个很大的问题,因为 ConfigurationManager 似乎在那里不可用。因此,我已将这两个字符串添加到门户中的 ConnectionStrings,但我找不到 Web 作业如何自动读取它们的好方法。我最终以这种方式自己从环境变量中读取了它们:

string dahsboard = Environment.GetEnvironmentVariable("CUSTOMCONNSTR_AzureWebJobsDashboard");
string storage = Environment.GetEnvironmentVariable("CUSTOMCONNSTR_AzureWebJobsStorage");

var configuration = new JobHostConfiguration();
configuration.DashboardConnectionString = dahsboard;
configuration.StorageConnectionString = storage;

JobHost host = new JobHost(configuration);
host.RunAndBlock();

但这是现在唯一的方法吗?还是有某种方法可以让 Web Job 像普通的 .Net 一样自行找到此设置?

最好将其设置为应用程序设置,而不是 Azure 门户中的连接字符串。这样,您就可以通过没有有趣前缀的简单名称(例如 AzureWebJobsDashboard)来引用它。通常,您应该避免对 CUSTOMCONNSTR_.

这样的前缀进行假设