我正在創建一封電子郵件,該電子郵件將發送指向 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 />"); }如果用戶在時間限制后單擊鏈接,是否可以將用戶重定向到設計的錯誤頁面?
1 回答

海綿寶寶撒
TA貢獻1809條經驗 獲得超8個贊
您可以在 Azure Blob 中設置靜態頁面。
您可以參考官方文檔來創建您的下載頁面,其中包含時間限制的邏輯。如果鏈接未過期,請下載它,如果過期,請跳轉到您的自定義錯誤頁面。
您可以上傳您的代碼DownloadPage.html
并修改代碼。的值uri
設置為?https://pan**storage.blob.core.windows.net/asset-*****-4baf-48a5-9ea1-6cb09319e679/DownloadPage.html?downloadurl=XXXXXXXX&expirationDate=2020-05-22 15:40:30
messageBody.Append("<a?href=\""?+?uri?+?"\"?download=\"MyGoogleLogo\">Download?Quote?PDF</a><br?/>");
中DownloadPage.html
,您可以通過參數檢查鏈接是否過期expirationDate
。
這只是一個建議,當然你也可以使用自己的應用網站進行更好的邏輯處理。
- 1 回答
- 0 關注
- 123 瀏覽
添加回答
舉報
0/150
提交
取消