本文介绍了检查下载链接是否在电子邮件中有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一封电子邮件,该电子邮件将发送指向Azure Blob容器中PDF的链接.我还在链接上播放了时间限制,因此30天后将不再起作用.这是我创建天蓝色链接和电子邮件消息的代码,如下所示:

 //与Azure建立连接.字符串storageConnection = CloudConfigurationManager.GetSetting("AzureBlobConnectionString");CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(storageConnection);//获取对报价blob容器的访问.CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("quotes");cloudBlobContainer.CreateIfNotExists(BlobContainerPublicAccessType.Blob);//将pdf插入Azure Blob.CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference("Quote_" + orderId +"_" + DateTime.Now.ToString("yyyy_MM_dd")+".pdf");;等待cloudBlockBlob.UploadFromStreamAsync(report.ExportToStream(ExportFormatType.PortableDocFormat));//创建30天的访问PDF的时间限制.DateTime expirationDate = DateTime.UtcNow.Add(new TimeSpan(30,0,0,0));SharedAccessBlobPolicy sharedAccessBlobPolicy = new SharedAccessBlobPolicy();sharedAccessBlobPolicy.SharedAccessExpiryTime = expirationDate;sharedAccessBlobPolicy.Permissions = SharedAccessBlobPermissions.Read;//创建具有时间限制的uri.字符串sharedAccesSignature = cloudBlockBlob.GetSharedAccessSignature(sharedAccessBlobPolicy);字符串uri = cloudBlockBlob.Uri.AbsoluteUri + sharedAccesSignature;StringBuilder messageBody =新的StringBuilder();messageBody.Append(附加了您的报价.< br/>< br/>"));if(additionalNotes.Replace(",").长度> 0){messageBody.Append(附加说明:< br/>"));messageBody.Append(additionalNotes +< br/>< br/>");}messageBody.Append(< a href = \""+ uri +" \"download = \" MyGoogleLogo \> Download Quote PDF</a>< br/>");messageBody.Append("b" ***链接将在30天后过期("+ expirationDate.ToString(" MM/dd/yyyy)+")***</b>< br/>< br/>);messageBody.Append(< b>请不要回复此电子邮件.</b>")); 

如果用户在时间限制后单击链接,是否可以将用户重定向到设计的错误页面?

解决方案

您可以在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 \>下载报价PDF</a>< br/>"); 

DownloadPage.html 中,可以通过参数 expirationDate 检查链接是否未过期.

这只是一个建议,当然,您也可以使用自己的应用程序网站进行更好的逻辑处理.

I am creating an email that will send out a link to a PDF in an Azure Blob Container. I am also playing a time limit on the link so it will no longer work after 30 days. Here is what my code that creates the azure link and email message looks like:

// 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 />");
            }
            messageBody.Append("<a href=\"" + uri + "\" download=\"MyGoogleLogo\">Download Quote PDF</a><br />");
            messageBody.Append("<b>*** Link will expire after 30 days (" + expirationDate.ToString("MM/dd/yyyy") + ") ***</b><br /><br />");
            messageBody.Append("<b>Please do not reply back to this email.</b>");

Is there a way to redirect the user to a designed error page if they click the link after the time limit?

解决方案

You can set static page in Azure Blobs.

You can refer the offical document to create your download page which contains the logic of time limit. If the link does not expire, download it, and if it expires, jump to your custom error page.

You can upload your DownloadPage.html,and modify code. The value of uri set like 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 />");

In the DownloadPage.html, you can check the link does not expire by parameter expirationDate.

This is just a suggestion, of course, you can also use your own application website for better logic processing.

这篇关于检查下载链接是否在电子邮件中有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:33