2

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:

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

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

return 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 :

This shows the access is to the Storage emulator which is not desired.

Question

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

Update based on the comment

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>
JTIM
  • 2,774
  • 1
  • 34
  • 74
  • Sorry, not very clear. Could you please clarify, what you receive, what you need to receive? URIs seem correct. – Alex Belotserkovskiy Apr 29 '16 at 12:09
  • @AlexBelotserkovskiy okay I will rewrite when I am at a pc. My question is that the URI scheme is completely different from Mobileservice. Why is this? Along the same lines the uri has devstoreaccount1 which isn't the name of the storage ? Is the URI because they exist in the same resourcegroup and therefore have local connection? (I can see that I was writing the question over too long time. I will rewrite, thank you for getting my attention pointed to this !) – JTIM Apr 29 '16 at 12:22
  • Devstoreaccount is the local storage emulator. 127.0.0.1 as well. Check what you have in your cloud configuration - if you see devstirageaccount that means your project targets something local – Alex Belotserkovskiy Apr 29 '16 at 12:34
  • Can you please show that cloud configuration setting? Removing sensitive information of course – Alex Belotserkovskiy Apr 29 '16 at 12:37
  • @AlexBelotserkovskiy okay, I will rewrite and add the information. Okay it should be the Azure service that I wanted to target. – JTIM Apr 29 '16 at 12:48
  • 1
    Thanks! No worries - your information provided is helpful as well for troubleshooting. – Alex Belotserkovskiy Apr 29 '16 at 12:53
  • @AlexBelotserkovskiy I have updated the question and added information about application settings from the azure portal. Or did you want some information from the web.config file? – JTIM Apr 29 '16 at 15:52
  • CloudConfigurationManager.GetSetting("MS_AzureStorageAccountConnectionString") that setting - could you show? – Alex Belotserkovskiy Apr 29 '16 at 15:55
  • @AlexBelotserkovskiy Updated, I have included the string. – JTIM Apr 29 '16 at 16:00
  • 1
    You may be interested in a new feature that will generate SAS tokens for you for the client, and has a lot less manual code. It also works with offline sync, so you can queue blob uploads/downloads to when you have an active connection. See [Connect to Azure Storage in your Xamarin.Forms app](https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-xamarin-forms-blob-storage/). – lindydonna May 20 '16 at 02:10

1 Answers1

1

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

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

Index view somewhere:

@ViewBag.LocalStorage
@ViewBag.CloudStorage

enter image description here

Alex Belotserkovskiy
  • 4,012
  • 1
  • 13
  • 10
  • Thank you so much for this help, I have a featured question (bonus) about one service to two clients, http://stackoverflow.com/questions/36402899/same-table-notification-hub-and-server-for-two-apps . Once again thank you this worked :) – JTIM Apr 30 '16 at 13:40
  • after this test it seemed to work, now that I have updated the client and created a new service the above code works fine. But I end with an error from the following `await container.CreateIfNotExistsAsync();` function. If you have time I would appreciate your help again http://stackoverflow.com/questions/37050344/create-blob-container-for-azure-app-service – JTIM May 05 '16 at 12:13