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);
}
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实现,不移动文件) 一起处理来防止文件盗链