【发布时间】:2016-08-23 20:42:53
【问题描述】:
我在从应用服务移动应用(非 MobileService)访问 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));
更新代码以使用新服务,但仍然没有帮助。数据连接似乎正确:
因此参考这些链接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);
返回值:
coud : Primary = 'http://127.0.0.1:10000/devstoreaccount1';次要 = 'http://127.0.0.1:10000/devstoreaccount1-secondary' http://127.0.0.1:10000/devstoreaccount1 临时存储:
这表明对Storage emulator 的访问是不希望的。
问题
如何获取Azure online storage 的Uri,例如从Azure app service 访问它。
根据评论更新
我将云配置请求解释为 azure 门户上 App Service 的应用程序设置。
<configuration>
<connectionStrings>
<add name="MS_AzureStorageAccountConnectionString" connectionString="DefaultEndpointsProtocol=https;AccountName=Name;AccountKey=key1_from_access_Keys" />
</connectionStrings>
<configuration>
【问题讨论】:
-
抱歉,不是很清楚。您能否澄清一下,您收到了什么,您需要收到什么? URI 似乎是正确的。
-
@AlexBelotserkovskiy 好的,我会在使用电脑时重写。我的问题是 URI 方案与 Mobileservice 完全不同。为什么是这样?同样,uri 有 devstoreaccount1 不是存储的名称? URI是因为它们存在于同一个资源组中,因此具有本地连接吗? (我可以看到我写的问题太久了。我会重写,谢谢你引起我的注意!)
-
Devstoreaccount 是本地存储模拟器。 127.0.0.1 也是如此。检查您的云配置中的内容 - 如果您看到 devstirageaccount 这意味着您的项目以本地为目标
-
谢谢!不用担心 - 您提供的信息对故障排除也很有帮助。
-
您可能对一项新功能感兴趣,该功能将为您为客户端生成 SAS 令牌,并且手动代码要少得多。它还适用于离线同步,因此您可以将 blob 上传/下载排队到您有活动连接时。见Connect to Azure Storage in your Xamarin.Forms app。
标签: c# azure azure-storage azure-web-app-service azure-blob-storage