c# - Azure 表存储 - 从只读 SAS token 创建连接字符串

标签 c# azure azure-table-storage

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

System.InvalidOperationException: No credentials provided. at 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();

最佳答案

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

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

关于c# - Azure 表存储 - 从只读 SAS token 创建连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40450992/

相关文章:

c# - 如何高性能存储地理散列数据

c# - .NET .application 安装程序文件?

c# - 如何生成 SAS token 以安全连接到 Azure IOT 中心

c# - Azure 存储队列中的重复检测

azure - 是否必须安装WALinuxAgent?

azure-storage - 使用 WAD 表时如何控制 Azure 中的 Azure 存储帐户成本

performance - 与旧版 TableServiceQuery 相比,为什么新的 Azure 存储客户端库 2.0 的查询性能较差?

c# - ASP.NET 身份验证 cookie

C# 模拟系统崩溃

c# - 模块通信在 DNN 中不起作用