BlobStorage.Advanced.CreateSharedAccessPolicyAsync C# (CSharp) Method

CreateSharedAccessPolicyAsync() private static method

Creates a shared access policy on the container.
private static CreateSharedAccessPolicyAsync ( Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container, string policyName ) : System.Threading.Tasks.Task
container Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer A CloudBlobContainer object.
policyName string The name of the stored access policy.
return System.Threading.Tasks.Task
        private static async Task CreateSharedAccessPolicyAsync(CloudBlobContainer container, string policyName)
        {
            // Create a new shared access policy and define its constraints.
            // The access policy provides create, write, read, list, and delete permissions.
            SharedAccessBlobPolicy sharedPolicy = new SharedAccessBlobPolicy()
            {
                // When the start time for the SAS is omitted, the start time is assumed to be the time when the storage service receives the request. 
                // Omitting the start time for a SAS that is effective immediately helps to avoid clock skew.
                SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
                Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List |
                    SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create | SharedAccessBlobPermissions.Delete
            };

            // Get the container's existing permissions.
            BlobContainerPermissions permissions = await container.GetPermissionsAsync();

            // Add the new policy to the container's permissions, and set the container's permissions.
            permissions.SharedAccessPolicies.Add(policyName, sharedPolicy);
            await container.SetPermissionsAsync(permissions);
        }