c# - 建议存储 Azure 存储连接字符串的位置在哪里

标签 c# azure connection-string azure-storage azure-webjobs

创建新的 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.WebJobsMicrosoft.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:

  1. Set the connection string named 'AzureWebJobsDashboard' in the connectionStrings section of the .config file in the following format

  2. Set the environment variable named 'AzureWebJobsDashboard'

  3. 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 。在生产中,您可以在 Azure 门户上指定相关的应用程序设置或连接字符串以覆盖您的开发设置。更多详情,您可以引用here以便更好地理解它。

What is the recommended place? Is connectionStrings only for database connection strings?

据我了解,当您使用第三方库时,您需要按照其说明进行配置。在编写代码时,您可以根据需要定义连接字符串并以相应的方式读取它们。

关于c# - 建议存储 Azure 存储连接字符串的位置在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47161161/

相关文章:

azure - 使用 Windows Azure Active Directory 的 SSO

c# - 无法从 pocketpc (windows mobile 6) 打开到 SQL Server 2005 的连接

c# - 如何在代码中添加 Entity Framework 6 提供程序?

c# - 在聚合框架 C# 中使用 Facets

c# - Math.NET Numerics - 来自 double 组的 Matrix<double>

node.js - 使用 Azure AD、ReactJS 和 NodeJS 对用户进行身份验证并使用 Graph API

azure - 使用 ARM 模板创建 Azure Web 应用程序后,我们可以将 Web 应用程序名称作为参数传递给 YAML 管道吗?

ASP.NET 连接字符串元数据语法

c# - 如何在 MVVM 中的 wpf 中设置来自资源的图像源

c# - WinForm应用程序重新启动?