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

大憨熊 提交于 2019-12-24 13:47:57

问题


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. It works properly for ordinary .net, but it's quite an issue with DNX, since it seems that ConfigurationManager is not available there. 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. 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?


回答1:


Your best best is to set it as an App Setting instead of a connection string in the Azure Portal. This way, you will be able to refer to it by simple name (e.g. AzureWebJobsDashboard) with no funny prefix. Generally, you should avoid building assumptions on prefixes like CUSTOMCONNSTR_.



来源:https://stackoverflow.com/questions/33301089/dnx-asp-net-5-console-app-as-azure-web-job-connection-strings-configuration-no

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