How do i find bloburl with shared access token expired? RRS feed

  • Question

  • I have written this below code to get the blob url with cache expiry token, actually I have set 2 hours to expire the blob url,
                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
                    // Create the blob client. 
                    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                    //Get a reference to the container.
                    CloudBlobContainer container = blobClient.GetContainerReference(containerName);
                    CloudBlockBlob blockBlob = container.GetBlockBlobReference("blobname");
                    //Create an ad-hoc Shared Access Policy with read permissions which will expire in 2 hours
                    SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
                        Permissions = SharedAccessBlobPermissions.Read,
                        SharedAccessExpiryTime = DateTime.UtcNow.AddHours(2),
                    //Set content-disposition header for force download
                    SharedAccessBlobHeaders headers = new SharedAccessBlobHeaders()
                        ContentDisposition = string.Format("attachment;filename=\"{0}\"", "blobname"),
                    var sasToken = blockBlob.GetSharedAccessSignature(policy, headers);
                    blobUrl = blockBlob.Uri.AbsoluteUri + sasToken;

    using this above code I get the blob URI with valid expiry token, now i want to check blob URI is valid or not in one client application. I tried web request and http client approach by passing the URL and get the response status code. if the response code is 404 then I assuming that the URL is expired if not the URL is still valid,but this approach taking more time.

    Please suggest me any other way.


    Tuesday, April 7, 2015 3:18 PM


  • Hi,

    If you are trying to test your code for the access time limit, you may change the "SharedAccessExpiryTime" for minutes and test it. If it is working as you wished for, then you can change it back to Hours.



    Tuesday, April 7, 2015 6:09 PM