azure - 从网络作业访问网站连接字符串

标签 azure connection-string azure-sql-database azure-webjobs

我一直在尝试通过 Azure 门户将连接字符串从 webjobs 的 App.config 文件移动到主机网站。我尝试过:

ConnectionStringSettings test = ConfigurationManager.ConnectionStrings["AzureDB"];

我还尝试使用 GetSetting 并将连接字符串作为键/值对放入配置选项的应用程序部分。

这仍然只显示我的本地连接字符串。我也尝试过使用 CloudConfigurationManager 但无济于事。

到处都有这样的例子,并且在SO中引用:

However, you don't have to set it in app.config for the web job if you set them in the portal. The WebJobs SDK knows how to read them from there.

那么我如何访问它们?

最佳答案

  1. 安装Microsoft Azure Configuration Manager
  2. 将连接字符串移至 appSetting 部分(用于调试目的)
  3. 使用CloudConfigurationManager检索连接字符串:

    var myConnectionString = CloudConfigurationManager.GetSetting("MyConnectionString");
    
  4. 您现在可以在 Azure 门户中管理连接字符串。

关于azure - 从网络作业访问网站连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29537581/

相关文章:

Azure Python SDK - 使用 CLI 凭据连接到 USGov 失败?

database - 根据暂存或生产切换 Azure ConnectionString

sql-server - 如何使用 SQL Server 在 azure 存储 blob 中创建文件

azure-sql-database - 无法使用 Databricks 从 Azure 突触读取数据,且出现主 key 错误

sql-server - 用户分配的托管标识的 SQL Azure 连接错误 'Login failed for user'

azure - 无法通过 Azure 混合连接访问本地 Web API

Azure 开发运营 : Compose Error: The current Compose file version is not compatible with your engine version

具有特定权限集的 Blob 存储的 Azure 角色

asp.net - 使用反射将连接字符串添加到 ConfigurationManager.ConnectionString 的危险

c# - asp.net core 2.2 不使用 WebApp Azure 配置中设置的 ConnectionString