我正在创建一封电子邮件,该电子邮件将发送指向 Azure Blob 容器中的 PDF 的链接。我还对链接设置了时间限制,因此 30 天后它将不再有效。这是创建天蓝色链接和电子邮件的代码:
// Establishes a connection with Azure.
string storageConnection = CloudConfigurationManager.GetSetting("AzureBlobConnectionString");
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(storageConnection);
// Gets access to the quote blob container.
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("quotes");
cloudBlobContainer.CreateIfNotExists(BlobContainerPublicAccessType.Blob);
// Inserts the pdf into Azure Blob.
CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference("Quote_" + orderId + "_" + DateTime.Now.ToString("yyyy_MM_dd") + ".pdf"); ;
await cloudBlockBlob.UploadFromStreamAsync(report.ExportToStream(ExportFormatType.PortableDocFormat));
// Creates the 30 day time limit to access the pdf.
DateTime expirationDate = DateTime.UtcNow.Add(new TimeSpan(30, 0, 0, 0));
SharedAccessBlobPolicy sharedAccessBlobPolicy = new SharedAccessBlobPolicy();
sharedAccessBlobPolicy.SharedAccessExpiryTime = expirationDate;
sharedAccessBlobPolicy.Permissions = SharedAccessBlobPermissions.Read;
// Creates the uri with the time limit.
string sharedAccesSignature = cloudBlockBlob.GetSharedAccessSignature(sharedAccessBlobPolicy);
string uri = cloudBlockBlob.Uri.AbsoluteUri + sharedAccesSignature;
StringBuilder messageBody = new StringBuilder();
messageBody.Append("Your Quote is attached.<br /><br />");
if (additionalNotes.Replace(" ", "").Length > 0)
{
messageBody.Append("Addtional Notes:<br />");
messageBody.Append(additionalNotes + "<br /><br />");
}
如果用户在时间限制后单击链接,是否可以将用户重定向到设计的错误页面?
海绵宝宝撒
相关分类