简体   繁体   中英

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). 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 )? 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. 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.
  2. When a user clicks the link it will check in the RouteHandler for a row existing in the table. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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