我正在創(chuàng)建一封電子郵件,該電子郵件將發(fā)送指向 Azure Blob 容器中的 PDF 的鏈接。我還對(duì)鏈接設(shè)置了時(shí)間限制,因此 30 天后它將不再有效。這是創(chuàng)建天藍(lán)色鏈接和電子郵件的代碼:// 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 />"); }如果用戶在時(shí)間限制后單擊鏈接,是否可以將用戶重定向到設(shè)計(jì)的錯(cuò)誤頁(yè)面?
檢查電子郵件中的下載鏈接是否有效
揚(yáng)帆大魚
2024-01-22 15:34:34