How to use SAS on StorageCredentials for Azure Table Storage?

廉价感情. 提交于 2019-12-12 18:27:22

问题


I create a SAS on a given table, using the .NET API:

        var tablePolicy = new SharedAccessTablePolicy()
        {
            SharedAccessExpiryTime = DateTime.Now.Add(TimeSpan.FromHours(2)),
            Permissions = SharedAccessTablePermissions.Query
        };
        var permissions = new TablePermissions();

        permissions.SharedAccessPolicies.Add("myPolicy", tablePolicy);

        var credentials = new StorageCredentials(
            "#my account here#",
            "#my account secondary key here#");
        var tableClient = new CloudTableClient(
            new Uri("https://#my account here#.table.core.windows.net/"),
            credentials);
        var logTable = tableClient.GetTableReference("WADLogsTable");

        logTable.SetPermissions(permissions);

        var sas = logTable.GetSharedAccessSignature(tablePolicy, "myPolicy", null, null, null, null);

I then take this last 'sas' variable and use it to create credentials and perform a query:

        var credentials = new StorageCredentials(sas);
        var tableClient = new CloudTableClient(
            new Uri("#my account URI here#"),
            credentials);
        var logTable = tableClient.GetTableReference("WADLogsTable");
        var rows = logTable.ExecuteQuery(new TableQuery()).ToArray();

I then receive a 403 (forbidden) error.

What did I do wrong?


回答1:


I believe you're getting this error because you're defining both SharedAccessTablePolicy and Policy Name when creating SAS. So if you use either of the following that should work:

var sas = logTable.GetSharedAccessSignature(tablePolicy, null, null, null, null, null);

or

var sas = logTable.GetSharedAccessSignature(null, "myPolicy", null, null, null, null);


来源:https://stackoverflow.com/questions/21442796/how-to-use-sas-on-storagecredentials-for-azure-table-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!