简体   繁体   English

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

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

In all of the manuals about how to get the Storage connection for azure web jobs it is said to have those two variables AzureWebJobsDashboard, AzureWebJobsStorage in the connection strings. 在所有有关如何获取Azure Web作业的存储连接的手册中,据说在连接字符串中都有这两个变量AzureWebJobsDashboard,AzureWebJobsStorage。 It works properly for ordinary .net, but it's quite an issue with DNX, since it seems that ConfigurationManager is not available there. 它对于普通的.net正常工作,但是对于DNX来说是个问题,因为那里似乎没有ConfigurationManager。 So I have added the two strings to the ConnectionStrings in the portal, but I cannot find a good way how the Web Job would read them automatically. 因此,我已经将两个字符串添加到门户网站的ConnectionStrings中,但是我找不到Web作业如何自动读取它们的好方法。 I ended up reading them myself from the Environment variables this way: 我最终以这种方式从环境变量中读取了它们:

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();

But is this the only way now or there is some way that will let Web Job find this settings on it's own like ordinary .Net will? 但这是现在唯一的方法,还是有某种方法可以让Web Job像普通的.Net一样自行找到此设置?

Your best best is to set it as an App Setting instead of a connection string in the Azure Portal. 最好的办法是将其设置为应用程序设置,而不是Azure门户中的连接字符串。 This way, you will be able to refer to it by simple name (eg AzureWebJobsDashboard ) with no funny prefix. 这样,您将可以通过简单的名称(例如AzureWebJobsDashboard )来引用它,而无需添加有趣的前缀。 Generally, you should avoid building assumptions on prefixes like CUSTOMCONNSTR_ . 通常,应避免在诸如CUSTOMCONNSTR_前缀上建立假设。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM