In my DownloadFile
page's Page_Load
method, the filename a user wishes to download is retrieved from the query string. The file is hosted in an Azure Blob Storage account. I am attempting to download the file using shared access signatures (SAS) via this approach:
var containerName = "containerName";
var con = "connectionString";
CloudStorageAccount account = CloudStorageAccount.Parse(con);
var blobClient = account.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);
var blob = container.GetBlockBlobReference("file.pdf");
var sasToken = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10),
}, new SharedAccessBlobHeaders()
{
ContentDisposition = "attachment; filename=file.pdf"
});
var blobUrl = string.Format("{0}{1}", blob.Uri.AbsoluteUri, sasToken);
Response.Redirect(blobUrl);
However, this does not download the file. Instead, the browser just shows a garbled character stream of the file:
The blobUrl
appears to be valid. But the Response.Redirect
isn't working as expected. Am I doing something wrong?
Note: I am using WebForms (unfortunately), not MVC
application/pdf
required? – GlennResponse.Redirect
is to redirect to that generated URL. – JoshG