存储 Azure 存储连接字符串的推荐位置是什么
What is the recommended place to store Azure Storage Connection strings
创建新的 WebJob 项目时,AzureWebJobsStorage 连接字符串添加到 App.config > 配置 > connectionStrings
相比之下,microsoft documentation for storage account connection strings 明确指出 AppSettings 是他们放置它的地方。
推荐的地方是什么? connectionStrings 仅用于数据库连接字符串吗?
我们将在 Azure Web 应用程序中使用连接字符串
When creating a new WebJob project, the AzureWebJobsStorage connection string is added to App.config > configuration > connectionStrings
当您创建 Azure WebJob 项目时,它会引用相关的 WebJob 库(Microsoft.Azure.WebJobs
、Microsoft.Azure.WebJobs.Core
)。您需要为 WebJob SDK 指定存储帐户以记录跟踪和指标数据。并且需要在配置文件的 connectionStrings 部分下指定连接字符串,否则会出现以下错误:
Microsoft Azure WebJobs SDK Dashboard connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways:
Set the connection string named 'AzureWebJobsDashboard' in the connectionStrings section of the .config file in the following format
Set the environment variable named 'AzureWebJobsDashboard'
Set corresponding property of JobHostConfiguration
据我了解,Azure WebJob SDK 仅支持从上述方法读取存储连接字符串。您也可以在appSettings部分设置连接字符串,此时需要在构造JobHostConfiguration
时指定相关属性如下:
static void Main()
{
var config = new JobHostConfiguration()
{
DashboardConnectionString= ConfigurationManager.AppSettings["AzureWebJobsDashboard"],
StorageConnectionString= ConfigurationManager.AppSettings["AzureWebJobsStorage"]
};
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
此外,您可以Use the Azure storage emulator for development and testing. While for production, you could specify the related app settings or connection strings on Azure Portal for overriding your dev settings. More details, you could refer to here更好地理解它。
What is the recommended place? Is connectionStrings only for database connection strings?
据我了解,当您使用第三方库时,您需要按照其说明进行配置。在编写代码时,您可以根据需要定义连接字符串并以相应的方式读取它们。
创建新的 WebJob 项目时,AzureWebJobsStorage 连接字符串添加到 App.config > 配置 > connectionStrings
相比之下,microsoft documentation for storage account connection strings 明确指出 AppSettings 是他们放置它的地方。
推荐的地方是什么? connectionStrings 仅用于数据库连接字符串吗?
我们将在 Azure Web 应用程序中使用连接字符串
When creating a new WebJob project, the AzureWebJobsStorage connection string is added to App.config > configuration > connectionStrings
当您创建 Azure WebJob 项目时,它会引用相关的 WebJob 库(Microsoft.Azure.WebJobs
、Microsoft.Azure.WebJobs.Core
)。您需要为 WebJob SDK 指定存储帐户以记录跟踪和指标数据。并且需要在配置文件的 connectionStrings 部分下指定连接字符串,否则会出现以下错误:
Microsoft Azure WebJobs SDK Dashboard connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways:
Set the connection string named 'AzureWebJobsDashboard' in the connectionStrings section of the .config file in the following format
Set the environment variable named 'AzureWebJobsDashboard'
Set corresponding property of JobHostConfiguration
据我了解,Azure WebJob SDK 仅支持从上述方法读取存储连接字符串。您也可以在appSettings部分设置连接字符串,此时需要在构造JobHostConfiguration
时指定相关属性如下:
static void Main()
{
var config = new JobHostConfiguration()
{
DashboardConnectionString= ConfigurationManager.AppSettings["AzureWebJobsDashboard"],
StorageConnectionString= ConfigurationManager.AppSettings["AzureWebJobsStorage"]
};
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
此外,您可以Use the Azure storage emulator for development and testing. While for production, you could specify the related app settings or connection strings on Azure Portal for overriding your dev settings. More details, you could refer to here更好地理解它。
What is the recommended place? Is connectionStrings only for database connection strings?
据我了解,当您使用第三方库时,您需要按照其说明进行配置。在编写代码时,您可以根据需要定义连接字符串并以相应的方式读取它们。