简体   繁体   English

如何编写asp.net网站的自过期下载链接的代码?

[英]How to write the code for self expiring download link for asp.net website?

I am planning to sell digital goods on my website (Asp.net). 我打算在我的网站(Asp.net)上出售数字商品。 After successful payment the customer will be redirected to the download page of my website, which will display the link to download the digital content stored in my server. 付款成功后,客户将被重定向到我网站的下载页面,该页面将显示下载我服务器中存储的数字内容的链接。

I want to secure the location of the file, by creating a disposable link to the file. 我想通过创建指向文件的一次性链接来保护文件的位置。 Every time a customer visits this page a new download link will be generated for the same file. 每次客户访问此页面时,都会为同一文件生成一个新的下载链接。 Also this link should expire after it is downloaded for the first time. 同样,此链接在首次下载后也应失效。

Is it possible to do it in asp.net ( C# preferably )? 是否可以在asp.net(最好是C#)中进行? if yes how can i do it? 如果是,我该怎么办?

If you want to the Link itself and not the query string to expire you will need to us MVC or at the very least URL routing in .NET. 如果要链接本身而不是查询字符串到期,则需要MVC或至少是.NET中的URL路由。 Then you will need to do the following: 然后,您需要执行以下操作:

  1. Create a table with the expiring URL (generate with using time or GUID generator), createdate & time, and how long before it expires. 使用到期的URL(使用时间或GUID生成器生成),创建时间和时间以及到期时间创建一个表。
  2. When a user clicks the link it will check in the RouteHandler for a row existing in the table. 当用户单击链接时,它将在RouteHandler中检入表中存在的行。 If the row exists and the createdate & time + expiration time is still greater than current time then show them the page. 如果该行存在并且创建的时间和到期时间仍大于当前时间,则向他们显示该页面。 Otherwise redirect them to whatever page you want. 否则,将它们重定向到所需的任何页面。

Yes it is possible. 对的,这是可能的。 One way would be to use handler (.ashx) files. 一种方法是使用处理程序(.ashx)文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM