CloudConfigurationManager.GetSetting返回null [英] CloudConfigurationManager.GetSetting returning null

查看:236
本文介绍了CloudConfigurationManager.GetSetting返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下说明这里我有:

  VAR的connectionString = CloudConfigurationManager.GetSetting(StorageConnectionString);

的connectionString ,这里是我的app.config:

 <?XML版本=1.0编码=UTF-8&GT?;
<结构>
  <&启动GT;
    < supportedRuntime版本=V4.0SKU =.net框架,版本= V4.5/>
  < /启动>
  <&是connectionStrings GT;
    <添加名称=StorageConnectionString
         的connectionString =DefaultEndpointsProtocol = https和帐户名=存储; AccountKey =键/>
  < /&是connectionStrings GT;
  <&运行GT;
    < assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
      < dependentAssembly>
        < assemblyIdentity名称=Microsoft.Data.OData公钥=31bf3856ad364e35文化=中性/>
        < bindingRedirect oldVersion =0.0.0.0-5.2.0.0NEWVERSION =5.2.0.0/>
      < / dependentAssembly>
    < / assemblyBinding>
  < /运行>
< /结构>


解决方案

好这个工程,即使意见不适合,因为我有一个裁判CloudConfigManager:


  

如果你正在创建一个没有参考Microsoft.WindowsAzure.CloudConfigurationManager的应用程序,并在连接字符串坐落在web.config或app.config中如上图,那么你可以使用ConfigurationManager中检索连接字符串。您将需要一个参考System.Configuration.dll添加到您的项目,并添加另一个命名空间声明的:


 使用System.Configuration;CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    ConfigurationManager.ConnectionStrings [StorageConnectionString]的ConnectionString)。

Following instructions here I have:

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

But connectionString is null, here is my 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>

解决方案

Well this works, even if the comment doesn't fit, because I do have a ref to CloudConfigManager:

If you are creating an application with no reference to Microsoft.WindowsAzure.CloudConfigurationManager, and your connection string is located in the web.config or app.config as show above, then you can use ConfigurationManager to retrieve the connection string. You will need to add a reference to System.Configuration.dll to your project and add another namespace declaration for it:

using System.Configuration;

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);

这篇关于CloudConfigurationManager.GetSetting返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆