我获得了一个具有只读访问权限的Azure表存储SAS令牌。我能够使用Azure存储资源管理器浏览它而不会出现问题。在尝试通过控制台应用程序访问它时,我能够使用SAS令牌解析连接字符串作为TableEndpoint但是当我尝试创建表客户端时,我得到:
System.InvalidOperationException:未提供凭据。 在Microsoft.WindowsAzure.Storage.CloudStorageAccount.CreateCloudTableClient()
我用于连接字符串(带有替换值)的语法是:
<add key="StorageConnectionString" value ="TableEndpoint=https://myaccount.table.core.windows.net/Table?sv=2015-04-05&tn=Table&sig=Signature&se=2099-99-99T12%3A00%3A00Z&sp=r" />
最后,我的控制台应用代码:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
答案 0 :(得分:6)
我认为你需要使用StorageCredentials
类。这是一个示例:
StorageCredentials accountSAS = new StorageCredentials(sasToken);
CloudStorageAccount accountWithSAS = new CloudStorageAccount(accountSAS, "account-name", endpointSuffix: null, useHttps: true);
CloudTableClient tableClientWithSAS = accountWithSAS.CreateCloudTableClient();
答案 1 :(得分:1)
您可以参考以下示例代码,使用表服务端点和共享访问签名来使用new CloudTableClient(Uri, StorageCredentials)
初始化CloudTableClient类的新实例。
StorageCredentials creds = new StorageCredentials("your SAStoken");
CloudTableClient tableClient = new CloudTableClient(new Uri("your table endpoint"), creds);
答案 2 :(得分:0)
在遇到相同问题时偶然发现了这个。使用StorageCredentials的解决方案似乎还可以,但后来我注意到上述连接字符串也存在问题。
为了使连接字符串有效,它必须包含“ SharedAccessSignature =”,因此您的连接字符串应为:
const screenHeight = Dimensions.get('window').height;
class Screen extends Component {
constructor(props) {
super(props);
}
render() {
return (
<ScrollView pagingEnabled>
<Page1 style={{height: screenHeight}} />
<Page2 style={{height: screenHeight}} />
</ScrollView>
);
}
}
我将其用于自己的情况,并且对我有用。
另请参阅latest release中的SAS令牌部分