繁体   English   中英

无法读取存储帐户和密钥-Azure

[英]Unable to read Storage account and key - Azure

我正在尝试将图像上传到Blob。 因此,在Web.Config中,我具有如下设置:

            <appSettings>
                <add key="webpages:Enabled" value="false" />
                <add key="StorageAccountName" value="storageaccount1"/> 
                <add key="StorageAccountKey" value="storageaccountkey1"/>
              </appSettings>

这是门户中的外观:

在此处输入图片说明

我的点网代码如下:

        public class ConnectionString
            {
                static string account = CloudConfigurationManager.GetSetting("StorageAccountName");
                static string key = CloudConfigurationManager.GetSetting("StorageAccountKey");
                public static CloudStorageAccount GetConnectionString()
                {
                    string connectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", account, key);
                    return CloudStorageAccount.Parse(connectionString);
                }
            }

但是,我的“ account”和“ key”变量返回NULL。

有人可以建议,我做错了吗? 有什么我想念的吗?

注意:我可以通过“ Azure Storage Explorer”上传图像。

CloudConfigurationManager.GetSetting("StorageAccountName"); 如果您在Web.config文件中对其进行配置,则应该可以使用。 我用Asp.net MVC文件对其进行测试。 它在我这边正常工作。

在此处输入图片说明

测试结果:

在此处输入图片说明

CloudConfigurationManager.GetSetting("MySetting")

它将从所有配置文件(即app.config,web.config和ServiceConfiguration.cscfg)读取值。

注意:如果我们的配置在Web.Debug.config的appsetting没有web.config文件,它会得到空值。

要读取web.config文件,请使用ConfigurationManager.AppSettings CloudConfigurationManager.GetSetting()用于实际读取.cscfg文件。

问题已解决。 我正在使用正在查看的web.config(这是错误的)。 .NET代码未更改。 通过使用正确的web.config解决了该问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM