Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Azure Blob存储Sas错误:身份验证失败_C#_Azure_Azure Storage Blobs_Sas Token - Fatal编程技术网

C# Azure Blob存储Sas错误:身份验证失败

C# Azure Blob存储Sas错误:身份验证失败,c#,azure,azure-storage-blobs,sas-token,C#,Azure,Azure Storage Blobs,Sas Token,我尝试在Azure Blob存储中使用SAS令牌,但出现以下错误: <Error> <Code>AuthenticationFailed</Code> <Message> Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

我尝试在Azure Blob存储中使用SAS令牌,但出现以下错误:

<Error>
  <Code>AuthenticationFailed</Code>
  <Message>
    Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:2aada4ff-901e-0011-116c-8bc84f000000 Time:2019-10-25T19:41:37.0381744Z
  </Message>
  <AuthenticationErrorDetail>
    Signature did not match. String to sign used was r 2019-10-25T19:26:51Z 2019-10-25T20:31:51Z /blob/platinepersistencesg/$root/documents-legal-entity-01d6d631-bc1e-54e7-894e-f67297a2bae7 2019-02-02 b
  </AuthenticationErrorDetail>
</Error>
这是我的密码:

public async Task<IActionResult> GetSasToken()
{
    const string containerName = "documents-legal-entity-01d6d631-bc1e-54e7-894e-f67297a2bae7";
    const string blobName = "09578f41-e7fb-4765-bf41-869ea649f03a.pdf";
    const SharedAccessBlobPermissions permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create;

    var blobClient = CloudStorageAccount
        .Parse("DefaultEndpointsProtocol=https;AccountName=<account_name>;AccountKey=<account_key>;EndpointSuffix=core.windows.net")
        .CreateCloudBlobClient();

    var container = blobClient.GetContainerReference(containerName);
    var blob = container.GetBlockBlobReference(blobName);
    var policy = new SharedAccessBlobPolicy
    {
        SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
        Permissions = permissions
    };
    var sasToken = blob.GetSharedAccessSignature(policy);
    var sasUri = container.Uri + sasToken;

    return Ok(new { uri = sasUri });
}
public异步任务GetSasToken()
{
const string containerName=“documents-legal-entity-01d6d631-bc1e-54e7-894e-f67297a2bae7”;
常量字符串blobName=“09578f41-e7fb-4765-bf41-869ea649f03a.pdf”;
const SharedAccessBlobPermissions permissions=SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create;
var blobClient=CloudStorageAccount

.Parse(“DefaultEndpointsProtocol=https;AccountName=”,但为了简单起见,我想改用Azure客户端,以避免携带存储密钥。

您唯一缺少的是URL构造中的blob名称。只需更改:

var sasUri=container.Uri+sasToken;

…到


var sasUri=blob.Uri+sasToken;

我们已经成功地使用_blobClient在公共访问模式下上传/下载blob,所以我认为问题不存在?我还是在我的问题中添加了它。是的,您的身份验证很好。我复制了您的错误并更新了上面的答案。请编辑您的问题,并包含您给我们的代码正在使用SAS URL进行上传。