本文介绍了来自Azure App Service的Blob存储访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从App Service移动应用程序(不是MobileService)访问Blob存储时遇到问题.我以前曾运行过MobileService,该服务通过以下方式访问Blob存储:

I have an issue with accessing blob storage from an App Service Mobile App (Not MobileService). I previously have had a MobileService running that accessed the Blob Storage in the following way:

// 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));

更新代码以在新服务上运行仍然没有帮助.数据连接似乎正确:

Updating the code to work on the new service, still did not help. The dataconnection seems correct:

因此请参考以下链接天蓝色配置 | azure连接字符串 | azure开始使用Blob存储.

Therefore referring to these links azure configuration | azure connection string | azure get started blob storage.

我已提取数据连接并实现了MS_AzureStorageAccountConnectionString.我有以下方法来验证是否找到了正确的访问权限:

I have extracted the data connection and have implemented the `MS_AzureStorageAccountConnectionString. I have the following methods to verify the correct access is found:

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);

返回值:

这表明不需要访问Storage emulator.

如何获取Azure online storageUri,例如从Azure app service进行访问.

How to get the Uri for the Azure online storage such as to access it from the Azure app service.

基于评论进行更新

我将对云配置的请求解释为azure门户上App Service的应用程序设置.

I interpreted the request for cloud configuration as the application settings for the App Service on the azure portal.

<configuration>
     <connectionStrings>
         <add name="MS_AzureStorageAccountConnectionString" connectionString="DefaultEndpointsProtocol=https;AccountName=Name;AccountKey=key1_from_access_Keys" />
     </connectionStrings>
<configuration>

推荐答案

我尝试使用您的代码来重新创建问题,这就是我所做的:

I tried to re-create the issue using your code, and that is what i done:

1)单击项目=>添加=>添加连接的服务=> Azure存储=>选择您的存储帐户.这样会将所有需要的库和有效的连接字符串安装到您的web.config中.

1) Click on the project => Add => Add Connected Service => Azure Storage => Select your storage account. That will install all of needed libraries and valid connection string into your web.config.

2)我将您的代码复制粘贴到HomeController Index操作中,并能够重新创建问题.基本上,您好像更改了值和变量.工作代码如下.第一个代码段用于Controller,第二个代码段应在索引视图中.我使用了MVC,您看起来像在使用Web API,应该没有什么区别.

2) I copy-pasted your code into the HomeController Index action and was able to re-create the issue. Basically, looks like you changed the values and variables.The working code is below. The first snippet is for Controller, the second should be in the Index view. I used MVC, and you looks like using Web API, should not make any difference.

string tempstorage = "";
        string cloud = "";
        try
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("allinazure_AzureStorageConnectionString"));
            cloud = storageAccount.BlobEndpoint.ToString() + "        " + storageAccount.BlobStorageUri.ToString();
        }
        catch
        {
        }

        try
        {
            CloudStorageAccount temp = CloudStorageAccount.DevelopmentStorageAccount;
            Uri endPoit = temp.BlobEndpoint;
            string uri = temp.BlobStorageUri.ToString();
            tempstorage = uri + "           " + endPoit.ToString();
        }
        catch
        {
        }
     ViewBag.LocalStorage = "cloud storage" + cloud;
        ViewBag.CloudStorage = "local storage : " + tempstorage;

        return View();

某处的索引视图:

@ViewBag.LocalStorage
@ViewBag.CloudStorage

这篇关于来自Azure App Service的Blob存储访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!