0

I am unable to access a public container using the C# SDK, even though I have enabled "Allow Blob public access" in the storage account configuration.

var fileSystemClient = new DataLakeFileSystemClient(new Uri("https://somestorageaccount.dfs.core.windows.net/public"), new DataLakeClientOptions());
var paths = fileSystemClient.GetPaths();
foreach (var path in paths)
{
    Console.WriteLine(path);
}

This code throws the following exception:

Azure.RequestFailedException: 'Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

Is there anything I can configure to make this work?

atefsawaed
  • 543
  • 8
  • 14

1 Answers1

0

I tried in my environment and got below results:

Initially, I created ADLS gen2 container with public access level set to container level.

Portal:

enter image description here

When I try to access the file through browser, I got same error.

Browser: enter image description here

When we are accessing through file system, Files kept in storage system are not accessible anonymously. It is necessary to authorize access even if it is public Access level. You are getting this error because you are attempting to access the resource without authorization.

If you need to access files, you need to authorize with SAS token. I tried with File URL + SAS token in the browser. I can be able to access the file.

You can get SAS-token by clicking file with generate SAS token.

enter image description here

Browser:

enter image description here

If you need access path of data lake gen 2 in C#, you use the StorageSharedKeyCredential method by this link:

string storageAccountName = StorageAccountName;
string storageAccountKey = StorageAccountKey;
Uri serviceUri = StorageAccountUri;

StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey);
DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential);
DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient(Randomize("sample-filesystem-list"));
List<string> names = new List<string>();
                
foreach (PathItem pathItem in filesystem.GetPaths())
    {
     names.Add(pathItem.Name);
     }

Reference: java - How to get list of child files/directories having parent DataLakeDirectoryClient class instance - Stack Overflow in java by Jim Xu.

Venkatesan
  • 3,748
  • 1
  • 3
  • 15
  • Thanks for you answer, but the solution you provided doesn't answer the question. I still need to provide an access key which contradicts the whole idea of a file being public. Is this the only way? – atefsawaed Dec 29 '22 at 18:38
  • Yes, please refer this https://stackoverflow.com/questions/35045880/cannot-access-windows-azure-file-storage-document/35046177#35046177 – Venkatesan Dec 30 '22 at 03:02