C#实现站点文件的防盗链

//download.aspx.cs
protected void Page_Load(object sender, EventArgs e)
    
{
        String fileUrl 
= Request.QueryString["file"].Trim().Replace("~"""); 
        
string DownloadFileName = Server.MapPath("~"+ fileUrl;
        
string filepath = DownloadFileName;
        
string filename = System.IO.Path.GetFileName(filepath);
        Response.Clear();
        Response.ContentType 
= "application/octet-stream";
        Response.AddHeader(
"Content-Disposition""attachment; filename=" + filename);
        Response.Flush();
        Response.WriteFile(filepath);
    }

C#动态修改文件夹名称(FSO实现,不移动文件) 一起处理来防止文件盗链
原文地址:https://www.cnblogs.com/ding0910/p/1023635.html