简体   繁体   English

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

[英]Development Storage Account Requires Authentication

I am using a CloudTableClient to access Table storage:我正在使用 CloudTableClient 访问表存储:

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"];

with the settings:使用设置:

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

but every time I try to retrieve a record from the 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;
}

I get the following error:我收到以下错误:

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

I am assuming this is related to https v http which dev storage uses but is there a way to allow this to authenticate so that I can use the TableClient as above or should I be doing this differently?我假设这与开发存储使用的 https v http 相关,但是有没有办法允许它进行身份验证,以便我可以像上面一样使用 TableClient 或者我应该以不同的方式这样做?

Please try the following code:请尝试以下代码:

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();
    }
}

Basically Storage Emulator has different endpoints than your regular Storage Accounts and when you create an instance of CloudStorageAccount using Storage Emulator credentials, the SDK thinks that you're trying to connect to an account named devstoreaccount1 in the cloud.基本上,存储模拟器具有与常规存储帐户不同的端点,当您使用存储模拟器凭据创建CloudStorageAccount实例时,SDK 认为您正在尝试连接到云中名为devstoreaccount1的帐户。 Because the key for devstoreaccount1 is not the same as the key for Storage Emulator account, you're getting 403 error.由于devstoreaccount1的密钥与存储模拟器帐户的密钥不同,因此您会收到 403 错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM