【问题标题】:Azure Table Storage - Create Connection String from a read-only SAS tokenAzure 表存储 - 从只读 SAS 令牌创建连接字符串
【发布时间】:2016-11-06 15:22:54
【问题描述】:

我获得了具有只读访问权限的 Azure 表存储 SAS 令牌。我可以使用 Azure 存储资源管理器毫无问题地浏览它。在尝试通过控制台应用程序访问它时,我能够使用 SAS 令牌作为 TableEndpoint 解析连接字符串,但是当我尝试创建 Table Client 时,我得到:

System.InvalidOperationException:未提供凭据。 在 Microsoft.WindowsAzure.Storage.CloudStorageAccount.CreateCloudTableClient()

我用于连接字符串(带有替换值)的语法是:

<add key="StorageConnectionString" value ="TableEndpoint=https://myaccount.table.core.windows.net/Table?sv=2015-04-05&amp;tn=Table&amp;sig=Signature&amp;se=2099-99-99T12%3A00%3A00Z&amp;sp=r" />

最后,我的控制台应用代码:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

【问题讨论】:

    标签: c# azure azure-table-storage


    【解决方案1】:

    我认为您需要使用 StorageCredentials 类。这是一个示例:

    StorageCredentials accountSAS = new StorageCredentials(sasToken);
    CloudStorageAccount accountWithSAS = new CloudStorageAccount(accountSAS, "account-name", endpointSuffix: null, useHttps: true);
    CloudTableClient tableClientWithSAS = accountWithSAS.CreateCloudTableClient();
    

    【讨论】:

      【解决方案2】:

      您可以参考以下示例代码,使用表服务端点和共享访问签名通过new CloudTableClient(Uri, StorageCredentials) 初始化 CloudTableClient 类的新实例。

      StorageCredentials creds = new StorageCredentials("your SAStoken");
      
      CloudTableClient tableClient = new CloudTableClient(new Uri("your table endpoint"), creds);
      

      【讨论】:

        【解决方案3】:

        遇到同样问题时偶然发现了这个。使用 StorageCredentials 的解决方案似乎没问题,但后来我注意到提到的连接字符串也有问题。

        为了使连接字符串有效,它需要包含“SharedAccessSignature=”,所以您的连接字符串应该是:

        TableEndpoint=https://myaccount.table.core.windows.net;SharedAccessSignature=sv=2015-04-05&amp;tn=Table&amp;sig=Signature&amp;se=2099-99-99T12%3A00%3A00Z&amp;sp=r
        

        我根据自己的情况使用了它,它对我有用。

        另请参阅https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string 中有关 SAS 令牌的部分

        【讨论】:

          猜你喜欢
          • 2020-12-10
          • 2022-07-19
          • 2015-12-02
          • 1970-01-01
          • 2022-01-17
          • 1970-01-01
          • 1970-01-01
          • 2018-11-05
          • 2020-05-30
          相关资源
          最近更新 更多