我在从App Service Mobile App(非移动服务)访问blob存储时遇到问题 . 我以前运行的MobileService以下列方式访问Blob存储:
// Set the URI for the Blob Storage service.
Uri blobEndpoint = new Uri(string.Format("https://{0}.blob.core.windows.net", storageAccountName));
// Create the BLOB service client.
CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint,
new StorageCredentials(storageAccountName, storageAccountKey));
更新代码以使用新服务仍然没有帮助 . dataconnection似乎是正确的:
因此,请参考这些链接azure configuration | azure connection string | azure get started blob storage .
我已经提取了数据连接并实现了`MS_AzureStorageAccountConnectionString . 我有以下方法来验证是否找到了正确的访问权限:
string tempstorage = "";
try
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("MS_AzureStorageAccountConnectionString"));
tempstorage = storageAccount.BlobEndpoint.ToString() + " " + storageAccount.BlobStorageUri.ToString();
//Uri blobEndpoint = storageAccount.TableStorageUri.GetUri(StorageLocation.Primary);
}
catch
{
}
string cloud = "";
try
{
CloudStorageAccount temp = CloudStorageAccount.DevelopmentStorageAccount;
Uri endPoit = temp.BlobEndpoint;
string uri = temp.BlobStorageUri.ToString();
cloud = uri + " " + endPoit.ToString();
}
catch
{
}
return Ok("coud : " + cloud + " temp storage : " + tempstorage);
回报 Value :
coud:Primary ='http://127.0.0.1:10000/devstoreaccount1'; Secondary ='http://127.0.0.1:10000/devstoreaccount1-secondary'http://127.0.0.1:10000/devstoreaccount1 temp storage:
这表明访问是不希望的 Storage emulator
.
问题
如何获取 Azure online storage
的 Uri
,例如从 Azure app service
访问它 .
Update based on the comment
我将 Cloud 配置请求解释为azure门户上 App Service
的应用程序设置 .
<configuration>
<connectionStrings>
<add name="MS_AzureStorageAccountConnectionString" connectionString="DefaultEndpointsProtocol=https;AccountName=Name;AccountKey=key1_from_access_Keys" />
</connectionStrings>
<configuration>
1 回答
我尝试使用您的代码重新创建问题,这就是我所做的:
1)单击项目=>添加=>添加连接服务=> Azure存储=>选择您的存储帐户 . 这将在web.config中安装所有需要的库和有效的连接字符串 .
2)我将您的代码复制粘贴到HomeController Index操作中,并能够重新创建问题 . 基本上,看起来你改变了值和变量 . 工作代码如下 . 第一个片段用于Controller,第二个片段应该在Index视图中 . 我使用MVC,你看起来像使用Web API,应该没有任何区别 .
索引视图在某处: