Dynamic link loading algorithm

I saw a couple of sites that have a dynamic download link.

They request a valid email address and send a dynamically generated download link to that address. EX www.mysite.domain / hashvalue1

But how do they do it, since the file exists in the domain in a specific place? www.mysite.domain / downloads

Is there any guidebook?

+3
source share
3 answers

Yes, the web URL does not have to match the actual location of the file. The easiest way to implement this in .NET is to create an IHttpHandler that uses a Response.TransmitFile based on a hash value.

URL- : www.mysite.domain/file.ashx? hash = hashvalue1.

URL-, Routing (ASP.NET 3.5 SP1) - URL-.

+3

"UrlRewrite" ASP.NET HttpHandler.

UrlRewrite: http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

: Downlaod.ashx

using System;
using System.Web;

public class GetDownload : IHttpHandler 
{
    private static string file = "your file location";
    public void ProcessRequest (HttpContext context) 
    {
        if(UsersHasRights(context)) 
        {
            context.Response.TransmitFile(file);
        }
    }

    public bool IsReusable 
    {
        get { return false; }
    }
}
+4

, . , , . , , , . , ( ) . .

You can send a link to a user, such as this site.com/files.dld?hash, and implement IHttpHandler to handle this extension (see this answer by Andrey Shchekin). Here is also an article describing how to use HttpHandler to download zip files.

0
source

Source: https://habr.com/ru/post/1718682/


All Articles