wes*_*ton 22 c# app-config azure azure-storage
var connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");
Run Code Online (Sandbox Code Playgroud)
但connectionString是null,这里是我的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>
Run Code Online (Sandbox Code Playgroud)
das*_*los 18
有同样的问题.而不是使用连接字符串,使用配置 - > appSettings->这样的添加键...
<configuration>
<appSettings>
<add key="StorageConnectionString" value="[ConnectionStringHere]" />
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这很有用,即使评论不合适,因为我确实有一个参考CloudConfigManager:
如果您创建的应用程序没有引用Microsoft.WindowsAzure.CloudConfigurationManager,并且您的连接字符串位于web.config或app.config中,如上所示,则可以使用ConfigurationManager检索连接字符串.您需要向项目添加对System.Configuration.dll的引用,并为其添加另一个名称空间声明:
using System.Configuration;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
Run Code Online (Sandbox Code Playgroud)
我有同样的问题.我已将项目更新为使用Azure SDK 2.0.我为我的Web和辅助角色更新了NuGet包,但Visual Studio中的Azure项目仍然是旧版本.
要解决此问题,请右键单击Azure项目,然后选择"属性".在"应用程序"选项卡下,您将看到一个用于更新Azure SDK的按钮.