我正在创建一封电子邮件,该电子邮件将发送指向 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 关注
- 71 浏览
添加回答
举报
0/150
提交
取消