本文介绍了CloudConfigurationManager.GetSetting 返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按照说明此处我有:
var connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");
但是connectionString
是null
,这是我的app.config:
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>
推荐答案
这很好用,即使评论不合适,因为我确实有对 CloudConfigManager 的引用:
Well this works, even if the comment doesn't fit, because I do have a ref to CloudConfigManager:
如果您正在创建一个不引用 Microsoft.WindowsAzure.CloudConfigurationManager 的应用程序,并且您的连接字符串位于 web.config 或 app.config 中,如上所示,那么您可以使用 ConfigurationManager 来检索连接字符串.您需要在项目中添加对 System.Configuration.dll 的引用,并为其添加另一个命名空间声明:
using System.Configuration;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
这篇关于CloudConfigurationManager.GetSetting 返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!