Azure storage emulator - blob creation gives 403 Forbidden message

前端 未结 5 1422
没有蜡笔的小新
没有蜡笔的小新 2020-12-16 16:41

I am attempting to use the Azure Storage Emulator to work with blob storage. I just cannot seem to get it to work and have wasted an entire day trying without success. I kee

相关标签:
5条回答
  • 2020-12-16 16:57
    container.SetPermissions(
                        new BlobContainerPermissions
                        {
                            PublicAccess =
                                BlobContainerPublicAccessType.Blob
                        });
    

    When initialize connection. But first, use a Client for Storage and change permission of container using the Client.

    Works for me ;)

    0 讨论(0)
  • 2020-12-16 17:03

    Just saw this with WindowsAzure.Storage 8.6.0. I followed this issue's comments and the fix that worked for me is to add the following to ExcludeComponentCorrelationHttpHeadersOnDomains in ApplicationInsights.config:

    <Add>localhost</Add>
    <Add>127.0.0.1</Add>
    

    Seems like at some point a regression was introduced that causes AI to modify the headers for requests to the emulator which results in the 403 Forbidden error.

    0 讨论(0)
  • 2020-12-16 17:03

    As mentioned on earlier posts please don't use "devstoreaccount1" account for connecting to Azure storage emulator . Instead use only ""UseDevelopmentStorage=true"" as connection string and attached devstorage DB instead "devstoreaccount1".

    Complete example: In config:

      add name ="ConnString" connectionString="UseDevelopmentStorage=true"
    .....
    

    In code:

       string connStr = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;            
       CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connStr);
    

    Now connect to devStorage account either by Storage Explorer or by Server Explorer (VSTS) and monitor your DB operations.

    0 讨论(0)
  • 2020-12-16 17:14

    Quite frankly I am a little annoyed that the original code did not work. After all, the MSDN article by Microsoft (https://azure.microsoft.com/en-us/documentation/articles/storage-use-emulator/) clearly states we should use:

    Account name: devstoreaccount1 Account key: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==

    So why the heck did that not work?

    Basically storage emulator has different endpoints than the cloud storage account. For example, the default blob endpoint for a cloud storage account is http://[youraccount].blob.core.windows.net while the blob endpoint for storage emulator is http://127.0.0.1:10000. When you just specify the storage account name and key for the storage emulator in your connection string, storage client library treats it like a cloud storage account and tries to connect to http://devstoreaccount1.blob.core.windows.net using the account key you provided. Since the key for devstoreaccount1 in the cloud is not the one you provided, you get 403 error.

    If you want to connect to storage emulator using account name and key, you would need to provide additional details like different endpoints. So your connection string would be something like:

    var connectionString = @"DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;
    AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;
        BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;
        TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;
        QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;";
    

    Notice the endpoints I have specified in the connection string.

    var connectionString = "UseDevelopmentStorage=true";
    

    The code above is just the short form of the big connection string I specified above.

    Hope this clarifies your doubt.

    0 讨论(0)
  • 2020-12-16 17:20

    I figured it out!! Or more appropriately I found the answer here: https://stackoverflow.com/a/17500876/1400153

    In the code I posted above, I changed the lines

    // Retrieve storage account from connection string
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["EmulatorStorageConnectionString"]);
    

    to

    var connectionString = "UseDevelopmentStorage=true";
    var storageAccount = CloudStorageAccount.Parse(connectionString);
    

    That is literally the only change I made to the code.

    In addition, I right clicked the emulator icon in the windows taskbar > Show storage emulator UI, and I clicked the Reset button. Not sure if this helped, I'm just documenting the two things I did for the next guy who gets stuck on this.

    And now it works...

    Quite frankly I am a little annoyed that the original code did not work. After all, the MSDN article by Microsoft (http://msdn.microsoft.com/en-us/library/windowsazure/hh403989.aspx) clearly states we should use:

    Account name: devstoreaccount1 Account key: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==

    So why the heck did that not work? That article was updated July 2012 so it is not exactly outdated. So many hours wasted... but at least I can go to sleep now knowing that I finally got something working :)

    0 讨论(0)
提交回复
热议问题