c# - CloudConfigurationManager.GetSetting 返回 null

标签 c# azure app-config azure-storage

以下说明 here我有:

var connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");

但是connectionStringnull,这是我的app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <connectionStrings>
    <add name="StorageConnectionString"
         connectionString="DefaultEndpointsProtocol=https;AccountName=storage;AccountKey=key" />
  </connectionStrings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

最佳答案

遇到同样的问题。不要使用连接字符串,而是使用配置->appSettings->添加键,如下所示...

<configuration>
    <appSettings>
        <add key="StorageConnectionString" value="[ConnectionStringHere]" />
    </appSettings>
</configuration>

关于c# - CloudConfigurationManager.GetSetting 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15384186/

相关文章:

c# - Azure 文件存储 : Error 400 (Condition headers are not supported. )

c# - 在 C# .NET Framework 中使用 ConfigurationBuilder 我的应用服务设置去了哪里?

c# 错误 :Unrecognized configuration section userSettings - stop program reading user. 配置?

c# - 监听MySQL数据库变化

json - 基于 Azure ARM JSON 的变量标签

c# - 将 Delphi 指针和 stream.Read 转换为 C#

azure - 通过管道安装 Azure Functions 扩展

.net - Web.config 转换可以与 App.config 文件一起使用吗?

c# - 为什么这个从 short 到 int 的转换会失败?

c# - 使用 BindingNavigator 删除列表项,而不是正确的项