开发存储帐户需要身份验证

Development Storage Account Requires Authentication

我正在使用云Table客户端访问Table存储:

private StorageCredentials credentials;
public StorageCredentials StorageAccount
{
   get
   {
       if (credentials == null)
       {
           credentials = new StorageCredentials(config["AzureStorageSettings:AccountName"],
                                                 config["AzureStorageSettings:AccountKey"]);
       }

       return credentials;
   }
}

public CloudTableClient Tableclient
{
    get
    {
        var storageAccount = new CloudStorageAccount(StorageAccount, true);
        return storageAccount.CreateCloudTableClient();
    }
 }

 public string TableReference => config["CampaignStorageName"];

使用设置:

"AzureStorageSettings:AccountName": "devstoreaccount1",
"AzureStorageSettings:AccountKey": "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==",

但每次我尝试从 table

检索记录
public IngestionEntity GetIngestionRecord(IngestionMessage msg)
{
    var table = Tableclient.GetTableReference(TableReference);
    var retrieve = TableOperation.Retrieve<IngestionEntity>(msg.PartitionKey, msg.RowKey);

    var result = table.Execute(retrieve);

    log.LogInformation($"{msg.ToString()}, " +
           $"Query Status Code: {result.HttpStatusCode}, " +
           $"Cost: {result.RequestCharge}");

    return (IngestionEntity)result.Result;
}

我收到以下错误:

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

我假设这与开发存储使用的 https v http 有关,但是有没有办法允许它进行身份验证,以便我可以像上面那样使用 TableClient,或者我应该以不同的方式执行此操作?

请尝试以下代码:

private CloudStorageAccount storageAccount;
public CloudStorageAccount StorageAccount
{
    get
    {
        if (storageAccount == null)
        {
            storageAccount = config["AzureStorageSettings:AccountName"] == "devstoreaccount1" ? CloudStorageAccount.DevelopmentStorageAccount : new CloudStorageAccount(new StorageCredentials(config["AzureStorageSettings:AccountName"], config["AzureStorageSettings:AccountKey"]), true);
        }

        return storageAccount;
    }
}

public CloudTableClient Tableclient
{
    get
    {
        return StorageAccount.CreateCloudTableClient();
    }
}

基本上,存储模拟器的端点与您的常规存储帐户不同,当您使用存储模拟器凭据创建 CloudStorageAccount 的实例时,SDK 认为您正在尝试连接到名为 [=12] 的帐户=] 在云端。由于 devstoreaccount1 的密钥与存储模拟器帐户的密钥不同,您会收到 403 错误。