Azure容器共享访问签名到期

时间:2018-03-08 07:26:08

标签: azure-storage

我在Azure Blob和共享访问签名过期时遇到问题。我需要授予对blob超过1小时(1年)的访问权限,因此我使用了命名容器策略,但不幸的是。它在1小时后到期

SharedAccessPolicy sharedAccessPolicy = new SharedAccessPolicy();
    sharedAccessPolicy.Permissions = SharedAccessPermissions.Read;
    sharedAccessPolicy.SharedAccessStartTime = DateTime.UtcNow;
    //sharedAccessPolicy.SharedAccessExpiryTime = DateTime.UtcNow.AddYear(1); No need to define expiry time here.

    BlobContainerPermissions blobContainerPermissions = new BlobContainerPermissions();
    blobContainerPermissions.SharedAccessPolicies.Add("default", sharedAccessPolicy);

    container.SetPermissions(blobContainerPermissions);

    Console.WriteLine("Press any key to continue....");
    Console.ReadLine();
    CloudBlob blob = container.GetBlobReference(path);

    string sas = blob.GetSharedAccessSignature(new SharedAccessPolicy()
    {
        SharedAccessExpiryTime = DateTime.UtcNow.AddDays(7),//add expiry date only when you're creating the signed URL
    }
        , "default");

    Console.WriteLine(blob.Uri.AbsoluteUri + sas);

    Process.Start(new ProcessStartInfo(blob.Uri.AbsoluteUri + sas));

    Console.WriteLine("Press any key to continue....");
    Console.ReadLine();

0 个答案:

没有答案