azure - 无法读取存储帐户和密钥 - 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);
}
}
但是,我的“帐户”和“密钥”变量返回 NULL。
任何人都可以建议,我做错了什么?有什么我想念的吗?
注意:我可以通过“Azure 存储资源管理器”上传图像。
解决方案
CloudConfigurationManager.GetSetting("StorageAccountName");
如果你在Web.config文件中配置它应该可以工作。我用 Asp.net MVC 文件测试它。它在我这边正常工作。
测试结果:
CloudConfigurationManager.GetSetting("MySetting")
它将从所有配置文件(即 app.config、web.config 和 ServiceConfiguration.cscfg)中读取值。
注意:如果我们在Web.Debug.config而不是 web.config 文件中配置 appsetting,它将得到 null 值。
推荐阅读
- c# - 400 错误请求 | 从 ASP.NET Web API 接收自定义错误消息或模型
- c# - 根据索引连接两个数组
- node.js - 网络错误:getaddrinfo EMFILE dynamodb.eu-west-1.amazonaws.com:443
- spring - 在 Spring Hibernate 中使用 Session 方法使用 findByCriteria
- javascript - JS 数学方法的问题:函数正在删除多个最小值/最大值(我认为?)
- .net - 没有为 msversion 找到 cmake vs 编译器:4 (windows7)
- java - 如何使用 Spring 显示本地图像(保存在 C 盘上)?
- r - 删除分组条形图的 x 轴上因子(年)之间的空间
- amazon-web-services - 使用 AWS Beanstalk Hooks 执行 HTTP GET 请求
- php - 如何使用php“sprintf”在列类型“text”上使用“LIKE”过滤mysql